move code up one directory
[atutor.git] / mods / _standard / tile_search / tile.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require_once('classes/ResultParser.class.php');
18
19 $default_results_per_page = 20;
20
21 if (!isset($_REQUEST["results_per_page"])) $_REQUEST["results_per_page"] = $default_results_per_page;
22
23 if ($_REQUEST['submit'] || isset($_REQUEST['p']))
24 {
25         $keywords = trim($_REQUEST['keywords']);
26         //$title = trim($_REQUEST['title']);
27         //$description = trim($_REQUEST['description']);
28         //$author = trim($_REQUEST['author']);
29         $results_per_page = intval(trim($_REQUEST['results_per_page']));
30         
31         if($keywords <> "") 
32         // || $title <> "" || $description <> "" || $author <> "" || $_REQUEST["creativeCommons"] == "true"
33         {
34                 $page = intval($_REQUEST['p']);
35                 if (!$page) {
36                         $page = 1;
37                 }       
38         
39                 if ($results_per_page > $default_results_per_page || $results_per_page == 0)
40                         $results_per_page = $default_results_per_page;
41                 
42                 $startRecNumber = $results_per_page*($page - 1);
43                 
44                 $page_str = "results_per_page=".$results_per_page;
45                 $url_search = "&maxResults=".$results_per_page."&start=".$results_per_page*($page - 1);
46         
47                 if ($keywords <> "")
48                 {
49                         $page_str .= SEP."keywords=".urlencode($keywords);
50                         $url_search .= "&keywords=".urlencode($keywords);
51                 }
52         //      if ($title <> "") 
53         //      {
54         //              $page_str .= SEP."title=".urlencode($title);
55         //              $url_search .= "&title=".urlencode($title);
56         //      }
57         //      if ($description <> "") 
58         //      {
59         //              $page_str .= SEP. "description=".urlencode($description);
60         //              $url_search .= "&description=".urlencode($description);
61         //      }
62         //      if ($author <> "") 
63         //      {
64         //              $page_str .= SEP. "author=".urlencode($author);
65         //              $url_search .= "&author=".urlencode($author);
66         //      }
67         //      
68         //      if (isset($_REQUEST["search_type"])) 
69         //              $page_str .= SEP."search_type=".$_REQUEST["search_type"];
70         //      
71         //      if ($_REQUEST["search_type"] == 0) $url_search .= "&allKeyWords=true";
72         //      if ($_REQUEST["search_type"] == 1) $url_search .= "&anyKeyWords=true";
73         //      if ($_REQUEST["search_type"] == 2) $url_search .= "&exactPhraseKeyWords=true";
74         //      if ($_REQUEST["creativeCommons"] == "true") 
75         //      {
76         //              $page_str .= SEP. "creativeCommons=true";
77         //              $url_search .= "&creativeCommons=true";
78         //      }
79                 
80                 $url = AT_TILE_SEARCH_URL."?id=".$_config['transformable_web_service_id'].$url_search;
81         
82                 $xml_results = file_get_contents($url);
83                 
84                 if (!$xml_results)
85                 {
86                         $infos = array('CANNOT_CONNECT_SERVER', AT_TILE_SEARCH_URL);
87                         $msg->addError($infos);
88                 }
89                 else
90                 {
91                         $resultParser = new ResultParser();
92                         $resultParser->parse($xml_results);
93                         $result_list = $resultParser->getParsedArray();
94                         
95                         $savant->assign('result_list', $result_list);
96                         $savant->assign('startRecNumber', $startRecNumber+1);
97                         $savant->assign('results_per_page', $results_per_page);
98                         $savant->assign('page_str', $page_str);
99                 }
100         }
101 }
102
103 global $_custom_css, $onload;
104 $_custom_css = $_base_path . 'mods/_standard/tile_search/module.css'; // use a custom stylesheet
105 $onload = "document.form.keywords.focus();";
106
107 require (AT_INCLUDE_PATH.'header.inc.php');
108
109 $savant->display('tile_search/index.tmpl.php');
110
111 require(AT_INCLUDE_PATH.'footer.inc.php');
112 ?>