public function __construct(\SimpleXMLElement $action_xml)
 {
     if ($action_xml == NULL) {
         throw new e\EmptyValueException("The xml cannot be empty.");
     }
     if (self::DEBUG && self::DUMP) {
         DebugUtility::dump(u\XMLUtility::replaceBrackets($action_xml->asXML()));
     }
     $this->action_xml = $action_xml;
     $action_attr = $action_xml->attributes();
     $this->identifier = $action_attr->identifier->__toString();
     if ($action_attr->label) {
         $this->label = $action_attr->label->__toString();
     }
     if ($action_attr->move) {
         $this->move = $action_attr->move->__toString();
     } else {
         $this->move = "";
     }
     if ($action_attr->{"next-id"}) {
         $this->next_id = $action_attr->{"next-id"}->__toString();
     } else {
         $this->next_id = "";
     }
     $this->triggers = array();
     if ($this->action_xml->trigger) {
         foreach ($this->action_xml->trigger as $trigger) {
             $this->triggers[] = new TriggerDefinition($trigger);
         }
     }
 }
 public function displayXml()
 {
     $xml_string = htmlentities($this->getProperty()->xml);
     // &
     $xml_string = u\XMLUtility::replaceBrackets($xml_string);
     echo S_H2 . "XML" . E_H2 . S_PRE . $xml_string . E_PRE . HR;
     return $this;
 }
 public function displayScript()
 {
     $script_string = htmlentities($this->getProperty()->script);
     // &
     $script_string = u\XMLUtility::replaceBrackets($script_string);
     echo S_H2 . "Script" . E_H2 . S_PRE . $script_string . E_PRE . HR;
     return $this;
 }
 public function displayXml($formatted = true)
 {
     if ($formatted) {
         $xml_string = u\XMLUtility::replaceBrackets($this->xml);
         echo S_H2 . "XML" . E_H2 . S_PRE;
     }
     echo $xml_string;
     if ($formatted) {
         echo E_PRE . HR;
     }
     return $this;
 }
 public function displayXhtml()
 {
     if (!$this->hasStructuredData()) {
         $xhtml_string = u\XMLUtility::replaceBrackets($this->xhtml);
         echo S_H2 . 'XHTML' . E_H2;
         echo $xhtml_string . HR;
     }
     return $this;
 }
 public function displayXml()
 {
     $xml_string = u\XMLUtility::replaceBrackets($this->xml);
     echo S_H2 . "XML" . E_H2 . S_PRE . $xml_string . E_PRE . HR;
     return $this;
 }
 public static function assetTreeUpdatePage(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
 {
     $source_content = NULL;
     if (isset($params['source-cascade'])) {
         $source_cascade = $params['source-cascade'];
     } else {
         echo c\M::SOURCE_CASCADE_NOT_SET . BR;
         return;
     }
     if (isset($params['target-cascade'])) {
         $target_cascade = $params['target-cascade'];
     } else {
         echo c\M::TARGET_CASCADE_NOT_SET . BR;
         return;
     }
     if (isset($params['source-site'])) {
         $source_site = $params['source-site'];
     } else {
         echo c\M::SOURCE_SITE_NOT_SET . BR;
         return;
     }
     if (isset($params['target-site'])) {
         $target_site = $params['target-site'];
     } else {
         echo c\M::TARGET_SITE_NOT_SET . BR;
         return;
     }
     if (isset($params['exception-thrown'])) {
         $exception_thrown = $params['exception-thrown'];
     } else {
         echo c\M::EXCEPTION_THROWN_NOT_SET . BR;
         return;
     }
     if (isset($params['update-data'])) {
         $update_data = $params['update-data'];
     } else {
         $update_data = true;
     }
     if (isset($params['update-metadata'])) {
         $update_metadata = $params['update-metadata'];
     } else {
         $update_metadata = true;
     }
     try {
         $source_page = $child->getAsset($service);
         $source_page_path = u\StringUtility::removeSiteNameFromPath($source_page->getPath());
     } catch (\Exception $e) {
         throw new e\CascadeInstancesErrorException($e . BR . S_SPAN . "Path: " . $child->getPathPath() . E_SPAN);
     }
     // it will fail if there is any irregularity in the page
     if ($source_page->hasStructuredData()) {
         $source_page_dd = $source_page->getDataDefinition();
         $source_page_dd_path = u\StringUtility::removeSiteNameFromPath($source_page_dd->getPath());
         $source_page_dd_site = $source_page_dd->getSiteName();
         $target_page_dd_site = $source_page_dd_site;
         // compare the two data definitions
         $source_dd = Asset::getAsset($service, DataDefinition::TYPE, $source_page_dd_path, $source_page_dd_site);
         // data definition must be there
         $target_dd = $target_cascade->getAsset(DataDefinition::TYPE, $source_page_dd_path, $target_page_dd_site);
         $source_xml = new \SimpleXMLElement($source_dd->getXml());
         $target_xml = new \SimpleXMLElement($target_dd->getXml());
         if (!u\XMLUtility::isXmlIdentical($source_xml, $target_xml)) {
             throw new e\CascadeInstancesErrorException(S_SPAN . c\M::DIFFERENT_DATA_DEFINITIONS . E_SPAN);
         }
         $source_structured_data_std = $source_page->getStructuredData()->toStdClass();
         $target_dd_id = $target_dd->getId();
         $target_structured_data_std = $source_structured_data_std;
         $target_structured_data_std->definitionId = $target_dd_id;
     } else {
         $source_content = $source_page->getXhtml();
     }
     // content type
     $source_page_ct = $source_page->getContentType();
     $source_page_ct_path = u\StringUtility::removeSiteNameFromPath($source_page_ct->getPath());
     $source_page_ct_site = $source_page_ct->getSiteName();
     $target_page_ct_site = $source_page_ct_site;
     // content type must be there
     $target_page_ct = $target_cascade->getAsset(ContentType::TYPE, $source_page_ct_path, $target_page_ct_site);
     $source_page_path_array = u\StringUtility::getExplodedStringArray("/", $source_page_path);
     $source_page_path = $source_page_path_array[count($source_page_path_array) - 1];
     $source_page_parent_path = $source_page->getParentContainerPath();
     // create page
     $target_site_name = $target_site->getName();
     // parent must be there
     $target_parent = $target_cascade->getAsset(Folder::TYPE, $source_page_parent_path, $target_site_name);
     $target_page = $target_cascade->createPage($target_parent, $source_page_path, $target_page_ct, $source_content);
     // update data
     if ($update_data) {
         if ($target_page->hasStructuredData()) {
             try {
                 $target_service = $target_cascade->getService();
                 $identifiers = $source_page->getIdentifiers();
                 $identifier_asset_map = array();
                 $identifier_method_map = array();
                 $structured_data = new p\StructuredData($target_structured_data_std, $target_service);
                 foreach ($identifiers as $identifier) {
                     // store the resources
                     if ($source_page->isAssetNode($identifier)) {
                         $block_id = $source_page->getBlockId($identifier);
                         if (isset($block_id)) {
                             $resource_id = $block_id;
                             $source_resource_type = Block::getBlockType($service, $resource_id);
                         }
                         $file_id = $source_page->getFileId($identifier);
                         if (isset($file_id)) {
                             $resource_id = $file_id;
                             $source_resource_type = File::TYPE;
                         }
                         $page_id = $source_page->getPageId($identifier);
                         if (isset($page_id)) {
                             $resource_id = $page_id;
                             $source_resource_type = Page::TYPE;
                         }
                         $symlink_id = $source_page->getSymlinkId($identifier);
                         if (isset($symlink_id)) {
                             $resource_id = $symlink_id;
                             $source_resource_type = Symlink::TYPE;
                         }
                         if (isset($resource_id)) {
                             try {
                                 $source_resource = $service->retrieve($service->createId($source_resource_type, $resource_id));
                                 if ($service->isSuccessful()) {
                                     $source_resource_site = $source_resource->siteName;
                                     $source_resource_path = $source_resource->path;
                                     $target_resource_site = $source_resource_site;
                                     try {
                                         $asset = $target_cascade->getAsset($source_resource_type, $source_resource_path, $source_resource_site);
                                         $target_resource_id = $asset->getId();
                                         $identifier_asset_map[$identifier] = $asset;
                                         $resource_id = NULL;
                                     } catch (\Exception $e) {
                                         if ($exception_thrown) {
                                             throw new e\CascadeInstancesErrorException($e . BR . S_SPAN . "Path: " . $source_resource_path . E_SPAN);
                                         } else {
                                             DebugUtility::out($e->getMessage());
                                         }
                                     }
                                 }
                             } catch (\Exception $e) {
                                 if ($exception_thrown) {
                                     throw new e\CascadeInstancesErrorException($e);
                                 } else {
                                     DebugUtility::out($e->getMessage());
                                 }
                             }
                         }
                         // reinitialized for next round
                         $resource_id = NULL;
                     }
                 }
                 $identifiers = array_keys($identifier_asset_map);
                 $count = count($identifiers);
                 if ($count > 0) {
                     foreach ($identifiers as $identifier) {
                         $asset = $identifier_asset_map[$identifier];
                         $type = $asset->getType();
                         switch ($type) {
                             case 'file':
                                 $method = 'setFile';
                                 break;
                             case 'page':
                                 $method = 'setPage';
                                 break;
                             case 'symlink':
                                 $method = 'setSymlink';
                                 break;
                             default:
                                 $method = 'setBlock';
                         }
                         $identifier_method_map[$identifier] = $method;
                         // unplug everything from source
                         $structured_data->{$method}($identifier, NULL);
                         // unset method name
                         $method = NULL;
                     }
                 }
                 try {
                     $target_page->setStructuredData($structured_data);
                 } catch (\Exception $e) {
                     if ($exception_thrown) {
                         throw new e\CascadeInstancesErrorException($e);
                     } else {
                         DebugUtility::out($e->getMessage());
                     }
                 }
                 if ($count > 0) {
                     foreach ($identifier_method_map as $identifier => $method) {
                         $asset = $identifier_asset_map[$identifier];
                         $target_page->{$method}($identifier, $identifier_asset_map[$identifier]);
                     }
                 }
                 $target_page->edit();
             } catch (\Exception $e) {
                 if ($exception_thrown) {
                     throw new e\CascadeInstancesErrorException($e);
                 } else {
                     DebugUtility::out($e->getMessage());
                 }
             }
         }
         // page-level blocks and formats
         $map = self::getPageLevelBlockFormat($source_cascade, $source_page);
         foreach ($map as $config_name => $regions) {
             if (count($regions[0]) > 0) {
                 $region_map = $regions[0];
                 foreach ($region_map as $region => $block_format) {
                     if (isset($block_format['block'])) {
                         if (self::DEBUG) {
                             u\DebugUtility::out("Block " . $block_format['block']);
                         }
                         $type = Block::getBlockType($service, $block_format['block']);
                         if (self::DEBUG) {
                             u\DebugUtility::out("Type " . $type);
                         }
                         $source_block = $source_cascade->getAsset($type, $block_format['block']);
                         $source_block_path = u\StringUtility::removeSiteNameFromPath($source_block->getPath());
                         $source_block_site = $source_block->getSiteName();
                         if ($source_block_site == $source_page->getSiteName()) {
                             $target_block_site = $target_page->getSiteName();
                         } else {
                             $target_block_site = $source_block_site;
                         }
                         try {
                             $target_block = $target_cascade->getAsset($type, $source_block_path, $target_block_site);
                             $target_page->setRegionBlock($config_name, $region, $target_block)->edit();
                             if (self::DEBUG) {
                                 u\DebugUtility::out("Page: " . $target_page->getName() . " Region: " . $region);
                             }
                         } catch (\Exception $e) {
                             if ($exception_thrown) {
                                 throw new e\CascadeInstancesErrorException($e);
                             } else {
                                 DebugUtility::out($e->getMessage());
                             }
                         }
                     } else {
                         if (isset($block_format['no-block'])) {
                             $target_page->setRegionNoBlock($config_name, $region, true);
                         }
                     }
                     if (isset($block_format['format'])) {
                         if (self::DEBUG) {
                             u\DebugUtility::out("Format " . $block_format['format']);
                         }
                         $type = Format::getFormatType($service, $block_format['format']);
                         if (self::DEBUG) {
                             u\DebugUtility::out("Type " . $type);
                         }
                         $source_format = $source_cascade->getAsset($type, $block_format['format']);
                         $source_format_path = u\StringUtility::removeSiteNameFromPath($source_format->getPath());
                         $source_format_site = $source_format->getSiteName();
                         if ($source_format_site == $source_page->getSiteName()) {
                             $target_format_site = $target_page->getSiteName();
                         } else {
                             $target_format_site = $source_format_site;
                         }
                         try {
                             $target_format = $target_cascade->getAsset($type, $source_format_path, $target_format_site);
                             $target_page->setRegionFormat($config_name, $region, $target_format)->edit();
                             if (self::DEBUG) {
                                 u\DebugUtility::out("Page: " . $target_page->getName() . " Region: " . $region);
                             }
                         } catch (\Exception $e) {
                             if ($exception_thrown) {
                                 throw new e\CascadeInstancesErrorException($e);
                             } else {
                                 DebugUtility::out($e->getMessage());
                             }
                         }
                     } else {
                         if (isset($block_format['no-format'])) {
                             $target_page->setRegionNoFormat($config_name, $region, true);
                         }
                     }
                 }
             }
         }
     }
     $target_page->setMaintainAbsoluteLinks($source_page->getMaintainAbsoluteLinks())->setShouldBeIndexed($source_page->getShouldBeIndexed())->setShouldBePublished($source_page->getShouldBePublished())->edit();
     // commit everything before metadata
     // metadata
     if ($update_metadata) {
         $target_page->setMetadata($source_page->getMetadata());
     }
 }
<?php

require_once 'auth_tutorial7.php';
use cascade_ws_AOHS as aohs;
use cascade_ws_constants as c;
use cascade_ws_asset as a;
use cascade_ws_property as p;
use cascade_ws_utility as u;
use cascade_ws_exception as e;
try {
    $cascade->getAsset(a\TextBlock::TYPE, "388fa7a58b7ffe83164c93149320e775")->edit();
    echo u\XMLUtility::replaceBrackets($service->getLastRequest());
} catch (\Exception $e) {
    echo S_PRE . $e . E_PRE;
} catch (\Error $er) {
    echo S_PRE . $er . E_PRE;
}
/*
<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns1="http://www.hannonhill.com/ws/ns/AssetOperationService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Body>
    <ns1:edit>
      <ns1:authentication>
        <ns1:password>password</ns1:password>
        <ns1:username>username</ns1:username>
      </ns1:authentication>
      <ns1:asset>
        <ns1:textBlock>
          <ns1:id>388fa7a58b7ffe83164c93149320e775</ns1:id>
          <ns1:name>ajax-read-profile-php</ns1:name>
     }
     if ($mode != 'all') {
         break;
     }
 case 'list-sites':
     $sites = $cascade->getSites();
     foreach ($sites as $site) {
         echo $site->getPathPath() . BR;
     }
     if ($mode != 'all') {
         break;
     }
 case 'asset-tree':
     $site = $cascade->getSite('22q');
     $tree = $site->getAssetTree();
     echo S_PRE . u\XMLUtility::replaceBrackets($tree->toXml()) . E_PRE;
     if ($mode != 'all') {
         break;
     }
 case 'access-rights':
     $ari = $cascade->getAccessRights(a\Page::TYPE, '03b44ae28b7f085600adcd81311fbcdc');
     // test33
     echo S_PRE;
     var_dump($ari->toStdClass());
     echo E_PRE;
     /*               
                     
                 $user1 = $cascade->getAsset( a\User::TYPE, 'chanw' );
                 $user2 = $cascade->getAsset( a\User::TYPE, 'tuw' );
                 if( $ari->hasUser( $user1 ) )
                 {
<?php

require_once 'auth_tutorial7.php';
use cascade_ws_AOHS as aohs;
use cascade_ws_constants as c;
use cascade_ws_asset as a;
use cascade_ws_property as p;
use cascade_ws_utility as u;
use cascade_ws_exception as e;
try {
    $cascade->getAsset(a\TextBlock::TYPE, "388fa7a58b7ffe83164c93149320e775")->dump();
    echo u\XMLUtility::replaceBrackets($service->getLastResponse());
} catch (\Exception $e) {
    echo S_PRE . $e . E_PRE;
} catch (\Error $er) {
    echo S_PRE . $er . E_PRE;
}
/*
<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <readResponse xmlns="http://www.hannonhill.com/ws/ns/AssetOperationService">
      <readReturn>
        <asset>
          <assetFactory xsi:nil="true" />
          <assetFactoryContainer xsi:nil="true" />
          <connectorContainer xsi:nil="true" />
          <contentType xsi:nil="true" />
          <contentTypeContainer xsi:nil="true" />
          <dataDefinition xsi:nil="true" />
     //$s->removeRole( $r )->edit();
     if ($mode != 'all') {
         break;
     }
 case 'set':
     $s->setUrl('http://www.upstate.edu/tuw-test')->setDefaultMetadataSet(a\Asset::getAsset($service, a\MetadataSet::TYPE, 'b893fd058b7f0856002a5e11185ff809'))->setCssFile(NULL)->setSiteAssetFactoryContainer(a\Asset::getAsset($service, a\AssetFactoryContainer::TYPE, '04af3e2e8b7f085600e28886d7e2221d'))->setStartingPage(a\Asset::getAsset($service, a\Page::TYPE, '04af1d7a8b7f085600e28886865346c3'))->setSendReportOnErrorOnly(true)->addUserToSendReport(a\Asset::getAsset($service, a\User::TYPE, 'tuw'))->addGroupToSendReport(a\Asset::getAsset($service, a\Group::TYPE, 'hemonc'))->setRecycleBinExpiration(a\Site::NEVER)->edit();
     if ($mode != 'all') {
         break;
     }
 case 'publish':
     //$s->publish();
     if ($mode != 'all') {
         break;
     }
 case 'asset-tree':
     echo S_PRE . u\XMLUtility::replaceBrackets($s->getRootAssetFactoryContainerAssetTree()->toXml()) . E_PRE;
     if ($mode != 'all') {
         break;
     }
 case 'raw':
     $s_std = $service->retrieve($service->createId(c\T::SITE, $id), c\P::SITE);
     /*          
                 if( $s_std->timeToPublish == NULL )
                     unset( $s_std->timeToPublish );
                 else if( strpos( $s_std->timeToPublish, '-' ) !== false )
                 {
                     $pos = strpos( $s_std->timeToPublish, '-' );
                     $s_std->timeToPublish = substr( $s_std->timeToPublish, 0, $pos );
                 }
                 
                 if( $s_std->publishIntervalHours == NULL )