8ee271f67f825ce49d4249f5ca1d22adac9194e1
[atutor.git] / docs / mods / _standard / tile_search / index.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 = 25;
20 $default_results_per_page = 20;
21
22 $browse =  intval($browse);
23
24 if (!isset($_REQUEST["results_per_page"])) $_REQUEST["results_per_page"] = $default_results_per_page;
25
26 if ($_REQUEST['submit'] || isset($_REQUEST['p']))
27 {
28         $keywords = trim($_REQUEST['keywords']);
29         //$title = trim($_REQUEST['title']);
30         //$description = trim($_REQUEST['description']);
31         //$author = trim($_REQUEST['author']);
32         $results_per_page = intval(trim($_REQUEST['results_per_page']));
33         
34         if($keywords <> "") 
35         // || $title <> "" || $description <> "" || $author <> "" || $_REQUEST["creativeCommons"] == "true"
36         {
37                 $page = intval($_REQUEST['p']);
38                 if (!$page) {
39                         $page = 1;
40                 }       
41         
42                 if ($results_per_page > $default_results_per_page || $results_per_page == 0)
43                         $results_per_page = $default_results_per_page;
44                 
45                 $startRecNumber = $results_per_page*($page - 1);
46                 
47                 $page_str = "results_per_page=".$results_per_page;
48                 $url_search = "&maxResults=".$results_per_page."&start=".$results_per_page*($page - 1);
49         
50                 if ($keywords <> "")
51                 {
52                         $page_str .= SEP."keywords=".urlencode($keywords);
53                         $url_search .= "&keywords=".urlencode($keywords);
54                 }
55         //      if ($title <> "") 
56         //      {
57         //              $page_str .= SEP."title=".urlencode($title);
58         //              $url_search .= "&title=".urlencode($title);
59         //      }
60         //      if ($description <> "") 
61         //      {
62         //              $page_str .= SEP. "description=".urlencode($description);
63         //              $url_search .= "&description=".urlencode($description);
64         //      }
65         //      if ($author <> "") 
66         //      {
67         //              $page_str .= SEP. "author=".urlencode($author);
68         //              $url_search .= "&author=".urlencode($author);
69         //      }
70         //      
71         //      if (isset($_REQUEST["search_type"])) 
72         //              $page_str .= SEP."search_type=".$_REQUEST["search_type"];
73         //      
74         //      if ($_REQUEST["search_type"] == 0) $url_search .= "&allKeyWords=true";
75         //      if ($_REQUEST["search_type"] == 1) $url_search .= "&anyKeyWords=true";
76         //      if ($_REQUEST["search_type"] == 2) $url_search .= "&exactPhraseKeyWords=true";
77         //      if ($_REQUEST["creativeCommons"] == "true") 
78         //      {
79         //              $page_str .= SEP. "creativeCommons=true";
80         //              $url_search .= "&creativeCommons=true";
81         //      }
82                 
83                 $url = AT_TILE_SEARCH_URL."?id=".$_config['transformable_web_service_id'].$url_search;
84         
85                 $xml_results = file_get_contents($url);
86                 
87                 if (!$xml_results)
88                 {
89                         $infos = array('CANNOT_CONNECT_SERVER', AT_TILE_SEARCH_URL);
90                         $msg->addError($infos);
91                 }
92                 else
93                 {
94                         $resultParser = new ResultParser();
95                         $resultParser->parse($xml_results);
96                         $result_list = $resultParser->getParsedArray();
97                         
98                         $savant->assign('result_list', $result_list);
99                         $savant->assign('startRecNumber', $startRecNumber+1);
100                         $savant->assign('results_per_page', $results_per_page);
101                         $savant->assign('page_str', $page_str);
102                         $savant->assign('instructor_role', 1);
103                 }
104         }
105 }
106
107 global $_custom_css, $onload;
108 $_custom_css = $_base_path . 'mods/_standard/tile_search/module.css'; // use a custom stylesheet
109 $onload = "document.form.keywords.focus();";
110
111 require (AT_INCLUDE_PATH.'header.inc.php');
112
113 $savant->display('tile_search/index.tmpl.php');
114
115 require(AT_INCLUDE_PATH.'footer.inc.php');
116 ?>