summaryrefslogtreecommitdiffstats
path: root/sandbox/slaws/old/httpserver.php/htdocs/AlertDisplay.php
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/slaws/old/httpserver.php/htdocs/AlertDisplay.php')
-rw-r--r--sandbox/slaws/old/httpserver.php/htdocs/AlertDisplay.php274
1 files changed, 274 insertions, 0 deletions
diff --git a/sandbox/slaws/old/httpserver.php/htdocs/AlertDisplay.php b/sandbox/slaws/old/httpserver.php/htdocs/AlertDisplay.php
new file mode 100644
index 0000000000..94b5352818
--- /dev/null
+++ b/sandbox/slaws/old/httpserver.php/htdocs/AlertDisplay.php
@@ -0,0 +1,274 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<?php
+include 'SCA/SCA.php';
+
+/**
+ * @service
+ * @binding.restrpc
+ * @types http://tuscany.apache.org/sca/samples/aggregator/types ./Alerts.xsd
+ */
+class AlertDisplay
+{
+ /**
+ * @reference
+ * @binding.soap ./Alerts.wsdl
+ */
+ public $alert_service;
+
+ /**
+ * @reference
+ * @binding.soap ./AlertsSources.wsdl
+ */
+ public $alert_sources_service;
+
+ /**
+ * @return string
+ */
+ public function getAlertsHTMLTable()
+ {
+ $xmldas = SDO_DAS_XML::create("./Alerts.xsd");
+ $doc = $xmldas->loadFile("./Cached_Alerts.xml");
+ $cached_alerts = $doc->getRootDataObject();
+
+ // Use the alertService reference
+ $request = $this->alert_service->createDataObject("http://tuscany.apache.org/sca/samples/aggregator/service",
+ "getAllNewAlerts");
+ $request->parm = "AString";
+ $new_alerts = $this->alert_service->getAllNewAlerts($request);
+
+ foreach($new_alerts->parm->Alert as $alert){
+ $new_alert = $cached_alerts->createDataObject('Alert');
+ $new_alert->Title = $alert->Title;
+ $new_alert->Summary = $alert->Summary;
+ $new_alert->Address = $alert->Address;
+ $new_alert->Date = $alert->Date;
+ $new_alert->SourceId = $alert->SourceId;
+ $new_alert->Unread = true;
+ }
+
+ $return_table = "<TABLE border=\'0\'>";
+ $alert_id_number = 0;
+ foreach($cached_alerts->Alert as $alert){
+ $alert->Id = "alert_" . $alert_id_number;
+ $title = substr($alert->Title,0,80);
+ $summary = substr($alert->Summary,0,40);
+ $unread_string = $alert->Unread ? "unread_title" : "read_title";
+ $return_row = <<<ALERTROW
+<TR class="source_$alert->SourceId clickable" onclick="displayAlert('$alert->Address', '')">
+ <TD>
+ <SPAN id="$alert->Id" class="$unread_string">$title</SPAN>
+ <SPAN class="summary"> - $summary ...</SPAN>
+ </TD>
+ <TD>
+ $alert->Date
+ </TD>
+</TR>
+ALERTROW;
+ $return_table = $return_table . $return_row;
+ $alert_id_number += 1;
+ }
+ $return_table = $return_table . "</TABLE>";
+
+ // as php is one shot we have to save away the alerts we want to cache
+ $xmldas->saveFile($doc, "./Cached_Alerts.xml");
+
+ return $return_table;
+ }
+
+ /**
+ * @param string $alert_id
+ * @return string
+ */
+ public function readAlert($alert_id)
+ {
+ $xmldas = SDO_DAS_XML::create("./Alerter.xsd");
+ $doc = $xmldas->loadFile("./Cached_Alerts.xml");
+ $cached_alerts = $doc->getRootDataObject();
+
+ $return_summary = "";
+
+ foreach($cached_alerts->alert as $alert){
+ if (strcmp($alert->Id,$alert_Id) == 0){
+ SCA::$logger->log("Match");
+ $alert->Unread = false;
+ $return_summary = "<PRE>" . $alert->Summary . "</PRE>";
+ }
+ }
+
+ // as php is one shot we have to save away the alerts we want to cache
+ $xmldas->saveFile($doc, "./Cached_Alerts.xml");
+
+ return $return_summary;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAlertSourcesHTMLTable()
+ {
+ $request = $this->alert_sources_service->createDataObject("http://tuscany.apache.org/sca/samples/aggregator/sources",
+ "getAlertSources");
+ $request->parm = "AString";
+ $alert_sources = $this->alert_sources_service->getAlertSources($request);
+
+ $return_table = "<TABLE border='0'>\n";
+
+ $no_of_sources = 0;
+
+ foreach ($alert_sources->parm->Source as $alert_source){
+ $source_id = $alert_source->Id;
+ $return_row = <<<SOURCEROW
+<TR CLASS="source_$source_id" >
+ <TD CLASS="clickable" ONCLICK="displayAlert('$alert_source->Address', '')">
+ <IMG SRC="rss.png"/>&nbsp;&nbsp;$alert_source->Name
+ </TD>
+ <TD CLASS="clickable link" ONCLICK="showEditSource('$source_id')">Edit</TD>
+ <TD CLASS="clickable link" ONCLICK="deleteSource('$source_id')">Delete</TD>
+</TR>
+<TR ID="edit_source_$source_id" CLASS="hidden source_$source_id">
+ <TD COLSPAN="3">
+ <TABLE CLASS="sourceDetailsTable">
+ <TR>
+ <TD>Source name:</TD>
+ <TD>
+ <INPUT ID="source_{$source_id}_name" TYPE="TEXT" SIZE="50" VALUE="$alert_source->Name"/>
+ </TD>
+ </TR>
+ <TR>
+ <TD>Source address:</TD>
+ <TD>
+ <INPUT ID="source_{$source_id}_address" TYPE="TEXT" SIZE="50" VALUE="$alert_source->Address"/>
+ </TD>
+ </TR>
+ <TR>
+ <TD>
+ <INPUT ID="source_{$source_id}_type" TYPE="HIDDEN" VALUE="$source_id"/>
+ <INPUT TYPE="BUTTON" VALUE="Update" ONCLICK="updateSource('$source_id')"/>
+ <INPUT TYPE="BUTTON" VALUE="Cancel" ONCLICK="hideEditSource('$source_id')"/>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+</TR>
+SOURCEROW;
+ $return_table = $return_table . $return_row;
+ $no_of_sources = $no_of_sources + 1;
+ }
+
+ $source_id = $no_of_sources + 1;
+
+ $return_row = <<<ADDROW
+<TR CLASS="source_$source_id">
+ <TD COLSPAN="4" CLASS="clickable link" ONCLICK="showAddNewSource('$source_id')">Add new Alert Source</TD>
+</TR>
+<TR ID="add_source_$source_id" CLASS="hidden source_$source_id">
+ <TD COLSPAN="4">
+ <TABLE CLASS="sourceDetailsTable">
+ <TR>
+ <TD>Source name:</TD>
+ <TD>
+ <INPUT ID="source_{$source_id}_name" TYPE="TEXT" SIZE="50">
+ </TD>
+ </TR>
+ <TR>
+ <TD>Source address:</TD>
+ <TD>
+ <INPUT ID="source_{$source_id}_address" TYPE="TEXT" SIZE="50">
+ </TD>
+ </TR>
+ <TR>
+ <TD>Source type:</TD>
+ <TD>
+ <SELECT ID="source_{$source_id}_type" ONCHANGE="showSourceType('$source_id')">
+ <OPTION value="rss" selected="selected">RSS/Atom feed</OPTION>"
+ </SELECT>
+ </TD>
+ </TR>
+ <TR ID="add_rss_source">
+ <TD COLSPAN="2">
+ <TABLE CLASS="sourceDetailsTable">
+ <TR>
+ <TD>Feed address:</TD>
+ <TD>
+ <INPUT ID="source_{$source_id}_feedAddress" TYPE="TEXT" SIZE="50"/>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+ <TR>
+ <TD>
+ <INPUT TYPE="BUTTON" VALUE="Add" ONCLICK="addSource('$source_id')">
+ <INPUT TYPE="BUTTON" VALUE="Cancel" ONCLICK="hideAddNewSource('$source_id')">
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+</TR>
+ADDROW;
+
+ $return_table = $return_table . $return_row;
+ $return_table = $return_table . "</TABLE>\n";
+ return $return_table;
+ }
+
+ /**
+ * @param integer $source_id
+ * @return string
+ */
+ public function deleteAlertSource($source_id){
+ $this->alert_sources_service->removeAlertSource($source_id);
+ }
+
+ /**
+ * @param SingleSourceType $alert_source http://tuscany.apache.org/sca/samples/aggregator/types
+ */
+ public function addAlertSource($alert_source){
+ $request = $this->alert_sources_service->createDataObject("http://tuscany.apache.org/sca/samples/aggregator/sources",
+ "addAlertSource");
+ $source = $request->createDataObject("parm");
+
+ $source->Name = $alert_source->Name;
+ $source->Address = $alert_source->Address;
+ $source->Id = $alert_source->Id;
+ $source->Type = $alert_source->Type;
+
+ $this->alert_sources_service->addAlertSource($request);
+ }
+
+ /**
+ * @param SourceType $alert_source http://tuscany.apache.org/sca/samples/aggregator/types
+ */
+ public function updateAlertSource($alert_source){
+ $this->alert_sources_service->updateAlertSource($alert_source);
+ }
+}
+
+/* Some debugging lines
+ob_start();
+print_r( $new_alerts );
+$debug = ob_get_contents();
+ob_end_clean();
+SCA::$logger->log($debug);
+*/
+?>
+
+
+