77324db24b0322a4b05432fcb4a64089ce2eb322
[atutor.git] / mods / merlot / merlot_soap.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 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: merlot.php 6614 2006-09-27 19:32:29Z greg $
14
15 // Check if links is turned on for this course.
16 $sql ="SELECT home_links, main_links from ".TABLE_PREFIX."courses WHERE course_id=".$_SESSION[course_id];
17 $result = mysql_query($sql, $db);
18 while($row = mysql_fetch_assoc($result)){
19         if(ereg('links/index.php', $row['home_links']) || ereg('links/index.php', $row['main_links'])){
20                 $links = true;
21         }
22 }
23                 If(isset($_REQUEST['query'])){
24                         $search = stripslashes($_REQUEST['query']);
25                 }else if(isset($_REQUEST['advsearch'])){
26                         $search  = '<search>';
27                         if($_REQUEST['keywords'] != ''){
28                                 $keywords = stripslashes($_REQUEST['keywords']);
29                                 $search .= '<keyword>'.$keywords.'</keyword>';
30                         }
31
32                         if($_REQUEST['title'] != ''){
33                                 $title = stripslashes($_REQUEST['title']);
34                                 $search .= '<title>'.$title.'</title>';
35                         }
36
37                         if($_REQUEST['contributorName'] != ''){
38                                 $author = stripslashes($_REQUEST['contributorName']);
39                                 $search .= '<authorname>'.$author.'</authorname>';
40                         }
41
42                         if($_REQUEST['url'] != ''){
43                                 $url = stripslashes($_REQUEST['url']);
44                                 $search .= '<location>'.$url.'</location>';
45                         }
46
47                         if($_REQUEST['description'] != ''){
48                                 $description = stripslashes($_REQUEST['description']);
49                                 $search .= '<description>'.$description.'</description>';
50                         }
51
52                         if($_REQUEST['category'] != ''){
53                                 $category = intval($_REQUEST['category']);
54                                 $search .= '<category>'.$category.'</category>';
55                         }
56
57                         if($_REQUEST['language'] != ''){
58                                 $language = stripslashes($_REQUEST['language']);
59                                 $search .= '<language>'.$language.'</language>';
60                         }
61
62                         if($_REQUEST['materialType'] != ''){
63                                 $type = stripslashes($_REQUEST['materialType']);
64                                 $search .= '<learningresourcetype>'.$type.'</learningresourcetype>';
65                                 }
66
67                         if($_REQUEST['audience'] != ''){
68                                 $context = stripslashes($_REQUEST['audience']);
69                                 $search .= '<context>'.$context.'</context>';
70                         }
71
72                                 $search  .= '</search>';
73                 }
74
75                 $search_input = array($merlot_key, $search,'0','25');
76                 $client = new SoapClient($merlot_location);
77
78                 if($search && $search != '<search></search>'  && $search != ''){
79                         $results = $client->__soapCall('doSearch', $search_input);
80                         $results = get_object_vars($results);
81                         
82                         $result_count = count($results['resultElements']);
83                         echo '<div style="background-color:#eeeeee;width:95%;"><h3>'. _AT('merlot_results_found') .' - '.$results['totalResultsCount'].' -- '._AT('merlot_results_displayed').' '. $result_count.'</h3></div>';
84         
85                         for($i = 0; $i < $result_count; $i++){
86                                 $this_result =  get_object_vars($results['resultElements'][$i]);
87                                 if(fmod($i,2) ==0){
88                                         $bgstyle = "#ffffff";
89                                 }else{
90                                         $bgstyle = "#eeeeee";
91                                 }
92         
93                         echo '<div style="background-color:'.$bgstyle.';width:90%; margin: 10px; padding:3px;">';
94                         echo '<a href="'.$this_result['URL'].'" target="merlot">'.$this_result['title'].'</a> [ <a href="'.$this_result['detailURL'].'"  target="merlot">'._AT('merlot_full_record').'</a> ] ';
95
96                         // if links db is enabled for this course allow results to be added to it.
97                         if($this_result['numAssignments']){
98                                 echo '[ <a href="'.$this_result['assignmentsURL'].'"      target="merlot">'._AT('merlot_view_assignments').'</a> ]';
99                         }
100                         if($links == true){
101                                 echo '[ <a href="'.$_base_href.'mods/merlot/add_to_links.php?title='.urlencode($this_result['title']).SEP.'desc='.urlencode(substr($this_result['description'], 0,100)).SEP.'url='.urlencode($this_result['URL']).'">'._AT('merlot_add_to_link').'</a> ]';
102                         }       
103
104                         echo '<br/>'._AT('merlot_author').": ".$this_result['authorName'].'<br/>';
105                         echo _AT('merlot_description').": ".substr($this_result['description'], 0,200).'...<br/>';
106                         echo _AT('merlot_type').": ".$this_result['itemType'].'<br/>';
107                         echo _AT('merlot_creation_date').": ".date("F j, Y",strtotime($this_result['creationDate'])).'<br/>';
108                         echo '</div>';
109                         unset($this_result);
110                 }
111         }else if($results['totalResultsCount'] < 1){
112                         echo '<div style="background-color:#eeeeee;width:95%;"><h3>'. _AT('merlot_results_found', $result_count).' 0 </h3></div>';
113         }
114
115 ?>