made a copy
[atutor.git] / tile.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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
18 $path = array();
19
20 /* called at the start of en element */
21 /* builds the $path array which is the path from the root to the current element */
22 function startElement($parser, $name, $attrs) {
23         global $path;
24         array_push($path, $name);
25 }
26
27 /* called when an element ends */
28 /* removed the current element from the $path */
29 function endElement($parser, $name) {
30         global $my_data, $path, $tile_title, $tile_description, $tile_identifier;
31
32         if ($path == array('lom', 'general', 'title', 'langstring')) {
33                 $tile_title = $my_data;
34         } else if ($path == array('lom', 'general', 'description', 'langstring')) {
35                 $tile_description = $my_data;
36         } else if ($path == array('lom', 'general', 'identifier')) {
37                 $tile_identifier = $my_data;
38         }
39
40         $my_data = '';
41         array_pop($path);
42 }
43
44 /* called when there is character data within elements */
45 /* constructs the $items array using the last entry in $path as the parent element */
46 function characterData($parser, $data){
47         global $my_data;
48         $my_data .= $data;
49 }
50
51 require (AT_INCLUDE_PATH.'header.inc.php');
52
53 ?>
54 <form action="<?php echo $_SERVER['PHP_SELF']; ?>#search_results" method="get" name="form">
55
56 <div class="input-form" style="width: 40%">
57         <div class="row">
58                 <label for="words2"><?php echo _AT('search_words'); ?></label><br />
59                 <input type="text" name="query" size="40" id="words2" value="<?php echo stripslashes(htmlspecialchars($_GET['query'])); ?>" />
60         </div>
61
62         <div class="row">
63                 <?php echo _AT('search_in'); ?><br />
64
65                 <input type="radio" name="field" value="anyField" id="taf" <?php if (!isset($_GET['field']) || ($_GET['field'] == 'anyField')) { echo 'checked="checked"'; } ?> /><label for="taf"><?php echo _AT('tile_any_field'); ?></label><br />
66                 <input type="radio" name="field" value="title" id="tt" <?php if ($_GET['field'] == 'title') { echo 'checked="checked"'; } ?> /><label for="tt"><?php echo _AT('title'); ?></label><br />
67                 <input type="radio" name="field" value="author" id="ta" <?php if ($_GET['field'] == 'author') { echo 'checked="checked"'; } ?> /><label for="ta"><?php echo _AT('tile_author'); ?></label><br />
68                 <input type="radio" name="field" value="subject" id="tk" <?php if ($_GET['field'] == 'subject') { echo 'checked="checked"'; } ?> /><label for="tk"><?php echo _AT('tile_keyword'); ?></label><br />
69                 <input type="radio" name="field" value="description" id="td" <?php if ($_GET['field'] == 'description') { echo 'checked="checked"'; } ?> /><label for="td"><?php echo _AT('description'); ?></label><br />
70                 <input type="radio" name="field" value="technicalFormat" id="tf" <?php if ($_GET['field'] == 'technicalFormat') { echo 'checked="checked"'; } ?> /><label for="tf"><?php echo _AT('tile_technical_format'); ?></label>
71         </div>
72
73         <div class="row buttons">
74                 <input type="submit" name="submit" value="<?php echo _AT('search'); ?>" />
75         </div>
76 </div>
77 </form>
78 <br />
79 <?php
80
81 if (isset($_GET['query'])) {
82
83         if (!extension_loaded('soap')) {
84                 require(AT_INCLUDE_PATH . 'classes/nusoap.php');
85                 // Create the client instance
86                 $client = new nusoapclient(AT_TILE_WSDL, true);
87
88                 // Check for an error
89                 $error = $client->getError();
90                 if ($error) {
91                         // Display the error
92
93                         $msg->addError('TILE_UNAVAILABLE');
94                         $msg->printAll();
95
96                         require(AT_INCLUDE_PATH.'footer.inc.php');
97                         exit;
98                 }
99
100                 // Create the proxy
101                 $proxy = $client->getProxy();
102         } else {
103                 // Create the client instance
104                 $proxy = new soapclient(AT_TILE_WSDL);
105         }
106
107         $search_input = array('query' => $_GET['query'], 'field' => $_GET['field'], 'content' => 'contentPackage');
108
109         $results = $proxy->doSearch($search_input);
110
111
112         if ($results) {
113                 $num_results = count($results);
114         } else {
115                 $num_results = 0;
116         }
117         echo '<h3>'. _AT('results_found', $num_results).'</h3>';
118         if ($num_results) {
119                 echo '<ol>';
120                 foreach ($results as $result) {
121
122                         $xml_parser = xml_parser_create();
123
124                         xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
125                         xml_set_element_handler($xml_parser, 'startElement', 'endElement');
126                         xml_set_character_data_handler($xml_parser, 'characterData');
127
128                         if (!xml_parse($xml_parser, $result, true)) {
129                                 die(sprintf("XML error: %s at line %d",
130                                                         xml_error_string(xml_get_error_code($xml_parser)),
131                                                         xml_get_current_line_number($xml_parser)));
132                         }
133
134                         xml_parser_free($xml_parser);
135
136                         $tile_title = str_replace('<', '&lt;', $tile_title);
137
138                         echo '<li><strong>' . $tile_title . '</strong> - ';
139                         echo '<a href="'.AT_TILE_PREVIEW .'cp='.$tile_identifier.'&item='.$tile_identifier.'" target="_new">'._AT('preview').'</a>';
140                         echo ' | <a href="'.AT_TILE_EXPORT.'?cp='.$tile_identifier.'">'._AT('download').'</a>';
141                         echo '<br />';
142                         if (strlen($tile_description) > 200) {
143                                 echo '<small>' . $tile_description  . '</small>';
144                         } else {
145                                 echo $tile_description;
146                         }
147
148                         echo '<br /></li>';
149
150                         unset($tile_title);
151                         unset($tile_description);
152                         unset($tile_identifier);
153                 }
154                 echo '</ol>';
155         }
156 }
157         require(AT_INCLUDE_PATH.'footer.inc.php');
158 ?>