structAppend.module
Go to the documentation of this file.
00001 <?php 00002 00003 // $Id$ 00004 00005 00008 00018 // Include the utilities function used by the hooks and tools 00019 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/utilities.php'); 00020 00021 00037 function structAppend_main() 00038 { 00039 global $base_url; 00040 00041 drupal_set_html_head("<link type=\"text/css\" rel=\"stylesheet\" media=\"all\" href=\"" . $base_url . "/" 00042 . drupal_get_path("module", "structAppend") . "/css/style.css\" />"); 00043 00044 return (conStruct_append()); 00045 } 00046 00047 00079 function structAppend_access($op, $node, $account) 00080 { 00081 return TRUE; 00082 } 00083 00101 function structAppend_access_callback() 00102 { 00103 return TRUE; 00104 } 00105 00106 00137 function structAppend_block($op = 'list', $delta = 0, $edit = array()) 00138 { 00139 global $base_url; 00140 00141 // The $op parameter determines what piece of information is being requested. 00142 switch ($op) 00143 { 00144 case 'list': 00145 00146 // If $op is "list", we just need to return a list of block descriptions. 00147 // This is used to provide a list of possible blocks to the administrator, 00148 // end users will not see these descriptions. 00149 $blocks[0]['info'] = t('conStruct Append Tool'); 00150 return $blocks; 00151 00152 case 'configure': 00153 // If $op is "configure", we need to provide the administrator with a 00154 // configuration form. The $delta parameter tells us which block is being 00155 // configured. In this example, we'll allow the administrator to customize 00156 // the text of the first block. 00157 $form = array(); 00158 if ($delta == 0) 00159 { 00160 // All we need to provide is a text field, Drupal will take care of 00161 // the other block configuration options and the save button. 00162 $form['block_example_string'] = array( 00163 '#type' => 'textfield', 00164 '#title' => t('Block contents'), 00165 '#size' => 100, 00166 '#description' => t('This string will appear in the conStruct Tools menu'), 00167 '#default_value' => variable_get('conStruct_string', t('')) 00168 ); 00169 } 00170 00171 return $form; 00172 00173 case 'save': 00174 00175 // If $op is "save", we need to save settings from the configuration form. 00176 // Since the first block is the only one that allows configuration, we 00177 // need to check $delta to make sure we only save it. 00178 if ($delta == 0) 00179 { 00180 // Have Drupal save the string to the database. 00181 variable_set('structAppend_string', $edit['structAppend_string']); 00182 } 00183 return; 00184 00185 case 'view': 00186 00187 default: 00188 00189 // If $op is "view", then we need to generate the block for display 00190 // purposes. The $delta parameter tells us which block is being requested. 00191 switch ($delta) 00192 { 00193 case 0: 00194 // The subject is displayed at the top of the block. Note that it 00195 // should be passed through t() for translation. 00196 $block['subject'] = t('conStruct Append Tool'); 00197 // The content of the block is typically generated by calling a custom 00198 // function. 00199 $block['content'] = structAppend_contents(1); 00200 break; 00201 } 00202 return $block; 00203 } 00204 } 00205 00217 function structAppend_contents($which_block) 00218 { 00219 global $base_url; 00220 00221 if ($which_block == 1) 00222 { 00223 // Get the base path of the Drupal installation folder on the file system of the server 00224 $menuItems = ""; 00225 00226 if (user_access('access conStruct append')) 00227 { 00228 $localPath = $base_url . "/" . drupal_get_path("module", "structAppend") . "/imgs/"; 00229 00230 // For all users 00231 $menuItems .= "<img src=\"" . $localPath . "arrow_join.png\" style=\"padding-right:5px;\" alt=\"\" /><a href=\"" 00232 . $base_url . "/conStruct/append/\">Append</a><br />"; 00233 } 00234 00235 return variable_get('structAppend_menu', t($menuItems)); 00236 } 00237 } 00238 00256 function structAppend_menu() 00257 { 00258 $items = array(); 00259 00260 // Registration of the conStruct module settings page path 00261 /* 00262 $items['admin/settings/structAppend'] = array( 'title' => '', 00263 'description' => '', 00264 'page callback' => 'drupal_get_form', 00265 'page arguments' => array('structAppend_admin'), 00266 'access arguments' => array('access administration pages'), 00267 'type' => MENU_NORMAL_ITEM); 00268 */ 00269 // Registration of the main conStruct module page path 00270 $items['conStruct/append'] = array( 00271 'page callback' => 'structAppend_main', 00272 'access callback' => 'structAppend_access_callback', 00273 'type' => MENU_CALLBACK 00274 ); 00275 00276 return $items; 00277 } 00278 00279 00307 function structAppend_perm() 00308 { 00309 return array( 00310 'access conStruct append', 00311 'administer conStruct append' 00312 ); 00313 } 00314 00315 00328 function conStruct_append() 00329 { 00330 // Make sure the user has access to this tool 00331 if (!user_access('access conStruct append')) 00332 { 00333 return "<h2>" . t("You don't have access to this tool, sorry.") . "</h2>"; 00334 } 00335 else 00336 { 00337 // Display errors when in debug mode 00338 if (!isset($_GET['debug']) || $_GET['debug'] != 1) 00339 { 00340 ini_set("error_reporting", 0); 00341 } 00342 00343 $html = ""; 00344 00345 // upload ok 00346 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/WebServiceQuerier.php'); 00347 include_once('./' . drupal_get_path('module', 'conStruct') . '/framework/ProcessorXML.php'); 00348 00349 $step = ""; 00350 $source = ""; 00351 $sourceName = ""; 00352 $target = ""; 00353 $targetName = ""; 00354 $delete = FALSE; 00355 $userIP = "0.0.0.0"; 00356 00357 if(isset($_GET["step"])) 00358 { 00359 $step = $_GET["step"]; 00360 } 00361 00362 if(isset($_GET["source"])) 00363 { 00364 $source = $_GET["source"]; 00365 } 00366 00367 if(isset($_GET["target"])) 00368 { 00369 $target = $_GET["target"]; 00370 } 00371 00372 if(isset($_GET["sourceName"])) 00373 { 00374 $sourceName = $_GET["sourceName"]; 00375 } 00376 00377 if(isset($_GET["targetName"])) 00378 { 00379 $targetName = $_GET["targetName"]; 00380 } 00381 00382 if(isset($_GET["delete"])) 00383 { 00384 $delete = $_GET["delete"]; 00385 } 00386 00387 if(isset($_GET["userIP"])) 00388 { 00389 $userIP = $_GET["userIP"]; 00390 } 00391 00392 // the four possible steps of our workflow 00393 switch($step) 00394 { 00395 // The initial step 00396 default: 00397 case "source": 00398 { 00399 $html .= ' 00400 00401 <h1>'.t("Dataset Appending Tool").'</h1> 00402 <br /> 00403 <table style="background-color:#F4F7E7; border:1px solid #537407; 00404 padding:8px; vertical-align:middle;"> 00405 <tr> 00406 <td> 00407 <b>'.t("Steps:").'</b> 00408 </td> 00409 <td> 00410 <b>'.t("1. Set Source Dataset").'</b> 00411 </td> 00412 <td> 00413 '.t("2. Set Target Dataset").' 00414 </td> 00415 <td> 00416 '.t("3. Append Datasets").' 00417 </td> 00418 <td> 00419 '.t("4. Appending...").' 00420 </td> 00421 <td> 00422 '.t("5. Delete Source Dataset (Optional)").' 00423 </td> 00424 </tr> 00425 </table> 00426 <br /><br /> 00427 00428 '.t("The dataset appending tool is used to append the records of a source dataset to the records of a target 00429 dataset. Once the source got appended to the target, you will have the choice to delete the appended 00430 source dataset. All datasets available to you (from one or multiple data node instance) will be 00431 displayed in the drop-down box.").' 00432 00433 <br /><br /> 00434 00435 '.t("The first step is to select the source dataset you want to append:").' 00436 00437 <br /><br /> 00438 '; 00439 00440 // Now lets get the list of all datasets, from all related structWSF nodes, that the current 00441 // user has access to. 00442 00443 $availableDatasets = getAvailableDatasets(); 00444 00445 $html .= ' 00446 <script type="text/javascript"> 00447 function getName(sel) 00448 { 00449 var value = sel.options[sel.selectedIndex].text; 00450 00451 document.getElementById("sourceName").value = value; 00452 } 00453 </script>'; 00454 00455 // If we are not currently creating a resource, we display the form to create it 00456 $html .= "<br /><form action=\"" . $base_url . "/conStruct/append/\" method=\"get\"> 00457 <center> 00458 <table style=\"width: 400px;\"> 00459 <tr> 00460 <td><b>" . t("Source Dataset:") . "</b></td> 00461 <td> 00462 <select style=\"float:left;\" name=\"source\" size=\"1\">"; 00463 00464 $firstName = ""; 00465 foreach ($availableDatasets as $key => $dataset) 00466 { 00467 // If we are in face of a linked dataset, we have to use the linked dataset URI as the target URI 00468 // for this WSF query. 00469 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", ""); 00470 00471 $targetDataset = $dataset[0]; 00472 00473 if ($linkedDatasetRegistry != "") 00474 { 00475 foreach ($linkedDatasetRegistry as $key => $linkedDataset) 00476 { 00477 if ($dataset[0] == $linkedDataset) 00478 { 00479 $targetDataset = getDatasetFromUri("/datasets/" . $key . "/"); 00480 break; 00481 } 00482 } 00483 } 00484 00485 if($key == 0) 00486 { 00487 $firstName = check_plain($dataset[1]); 00488 } 00489 00490 $html .= " <option value=\"" . $targetDataset . " :: ".$dataset[2]."\" /> " . check_plain($dataset[1]); 00491 } 00492 00493 $html .= " </select> 00494 </td> 00495 </tr> 00496 00497 <tr> 00498 <td></td> 00499 <td> 00500 <br /> 00501 <input name=\"step\" type=\"hidden\" value=\"target\" /> 00502 <input name=\"sourceName\" id=\"sourceName\" type=\"hidden\" value=\"\" /> 00503 <input name=\"\" type=\"submit\" value=\"" . t("Next step: select target dataset") . "\" 00504 onclick=\"getName(source)\" /> 00505 </td> 00506 </tr> 00507 00508 00509 </table> 00510 </center> 00511 </form>"; 00512 00513 } 00514 break; 00515 case "target": 00516 { 00517 if($source == "") 00518 { 00519 header("Location: ../append/"); 00520 } 00521 00522 $html .= ' 00523 00524 <h1>'.t("Dataset Appending Tool").'</h1> 00525 <br /> 00526 <table style="background-color:#F4F7E7; border:1px solid #537407; 00527 padding:8px; vertical-align:middle;"> 00528 <tr> 00529 <td> 00530 <b>'.t("Steps:").'</b> 00531 </td> 00532 <td> 00533 '.t("1. Set Source Dataset").' 00534 </td> 00535 <td> 00536 <b>'.t("2. Set Target Dataset").'</b> 00537 </td> 00538 <td> 00539 '.t("3. Append Datasets").' 00540 </td> 00541 <td> 00542 '.t("4. Appending...").' 00543 </td> 00544 <td> 00545 '.t("5. Delete Source Dataset (Optional)").' 00546 </td> 00547 </tr> 00548 </table> 00549 <br /><br /> 00550 00551 '.t("The second step is to select the target dataset you want to append the source to:").' 00552 00553 <br /><br /> 00554 '; 00555 00556 // Now lets get the list of all datasets, from all related structWSF nodes, that the current 00557 // user has access to. 00558 00559 $availableDatasets = getAvailableDatasets(); 00560 00561 $html .= ' 00562 <script type="text/javascript"> 00563 function getName(sel) 00564 { 00565 var value = sel.options[sel.selectedIndex].text; 00566 00567 document.getElementById("targetName").value = value; 00568 } 00569 </script>'; 00570 00571 // If we are not currently creating a resource, we display the form to create it 00572 $html .= "<br /><form action=\"" . $base_url . "/conStruct/append/\" method=\"get\"> 00573 <center> 00574 <table style=\"width: 400px;\"> 00575 <tr> 00576 <td><b>" . t("Target Dataset:") . "</b></td> 00577 <td> 00578 <select style=\"float:left;\" name=\"target\" size=\"1\">"; 00579 00580 $firstName = ""; 00581 00582 foreach ($availableDatasets as $key => $dataset) 00583 { 00584 // Skip the display of the source dataset 00585 $sourceTest = explode(" :: ", $source); 00586 00587 if($dataset[0] == $sourceTest[0]) 00588 { 00589 continue; 00590 } 00591 00592 // If we are in face of a linked dataset, we have to use the linked dataset URI as the target URI 00593 // for this WSF query. 00594 $linkedDatasetRegistry = variable_get("Linked-Dataset-Registry", ""); 00595 00596 $targetDataset = $dataset[0]; 00597 00598 if ($linkedDatasetRegistry != "") 00599 { 00600 foreach ($linkedDatasetRegistry as $key => $linkedDataset) 00601 { 00602 if ($dataset[0] == $linkedDataset) 00603 { 00604 $targetDataset = getDatasetFromUri("/datasets/" . $key . "/"); 00605 break; 00606 } 00607 } 00608 } 00609 00610 if($key == 0) 00611 { 00612 $firstName = check_plain($dataset[1]); 00613 } 00614 00615 $html .= " <option value=\"" . $targetDataset . " :: ".$dataset[2]."\" /> " . check_plain($dataset[1]); 00616 } 00617 00618 global $user; 00619 00620 $userIP = variable_get("conStruct_AccessUser" . $user->uid, ""); 00621 00622 if ($userIP == "") 00623 { 00624 // If there is no IP for that user, we overload the IP of the node with "::" 00625 $userIP = "self::$user->uid"; 00626 } 00627 00628 $html .= " </select> 00629 </td> 00630 </tr> 00631 00632 <tr> 00633 <td></td> 00634 <td> 00635 <br /> 00636 <input name=\"step\" type=\"hidden\" value=\"append\" /> 00637 <input name=\"source\" type=\"hidden\" value=\"$source\" /> 00638 <input name=\"sourceName\" type=\"hidden\" value=\"$sourceName\" /> 00639 <input name=\"targetName\" id=\"targetName\" type=\"hidden\" value=\"$targetName\" /> 00640 <input name=\"userIP\" id=\"userIP\" type=\"hidden\" value=\"$userIP\" /> 00641 <input name=\"\" type=\"submit\" value=\"" . t("Next step: append datasets") . "\" 00642 onclick=\"getName(target)\" /> 00643 </td> 00644 </tr> 00645 00646 00647 </table> 00648 </center> 00649 </form>"; 00650 } 00651 break; 00652 case "append": 00653 { 00654 if($source == "" || $target == "") 00655 { 00656 header("Location: ../append/"); 00657 } 00658 00659 $html .= ' 00660 00661 <h1>'.t("Dataset Appending Tool").'</h1> 00662 <br /> 00663 <table style="background-color:#F4F7E7; border:1px solid #537407; 00664 padding:8px; vertical-align:middle;"> 00665 <tr> 00666 <td> 00667 <b>'.t("Steps:").'</b> 00668 </td> 00669 <td> 00670 '.t("1. Set Source Dataset").' 00671 </td> 00672 <td> 00673 '.t("2. Set Target Dataset").' 00674 </td> 00675 <td> 00676 <b>'.t("3. Append Datasets").'</b> 00677 </td> 00678 <td> 00679 '.t("4. Appending...").' 00680 </td> 00681 <td> 00682 '.t("5. Delete Source Dataset (Optional)").' 00683 </td> 00684 00685 </tr> 00686 </table> 00687 <br /><br /> 00688 00689 '.t("The third step is to confirm that you want to append the records of the source dataset 00690 to the ones of the target dataset:").' 00691 00692 <br /><br /> 00693 '; 00694 00695 $html .= "<br /><form action=\"" . $base_url . "/conStruct/append/\" method=\"get\"> 00696 <center> 00697 <table style=\"width: 600px;\"> 00698 <tr> 00699 <td align=\"center\"> 00700 00701 ".t("Are you sure you want to append records of <b>$sourceName</b> to the one 00702 of <b>$targetName</b>: ")." 00703 <br /> <br /> 00704 </td> 00705 </tr> 00706 <tr> 00707 <td align=\"center\"> 00708 <input name=\"step\" type=\"hidden\" value=\"appending\" /> 00709 <input name=\"source\" type=\"hidden\" value=\"$source\" /> 00710 <input name=\"sourceName\" type=\"hidden\" value=\"$sourceName\" /> 00711 <input name=\"target\" type=\"hidden\" value=\"$target\" /> 00712 <input name=\"targetName\" type=\"hidden\" value=\"$targetName\" /> 00713 <input name=\"userIP\" id=\"userIP\" type=\"hidden\" value=\"$userIP\" /> 00714 <input name=\"\" type=\"submit\" value=\"" . t("Append!") . "\" /> 00715 </td> 00716 </tr> 00717 </table> 00718 </center> 00719 </form>"; 00720 00721 00722 00723 } 00724 break; 00725 case "appending": 00726 { 00727 if($source == "" || $target == "") 00728 { 00729 header("Location: ../append/"); 00730 } 00731 00732 $html .= ' 00733 00734 <h1>'.t("Dataset Appending Tool").'</h1> 00735 <br /> 00736 <table style="background-color:#F4F7E7; border:1px solid #537407; 00737 padding:8px; vertical-align:middle;"> 00738 <tr> 00739 <td> 00740 <b>'.t("Steps:").'</b> 00741 </td> 00742 <td> 00743 '.t("1. Set Source Dataset").' 00744 </td> 00745 <td> 00746 '.t("2. Set Target Dataset").' 00747 </td> 00748 <td> 00749 '.t("3. Append Datasets").' 00750 </td> 00751 <td> 00752 <b>'.t("4. Appending...").'</b> 00753 </td> 00754 <td> 00755 '.t("5. Delete Source Dataset (Optional)").' 00756 </td> 00757 00758 </tr> 00759 </table> 00760 <br /><br /> 00761 '; 00762 00763 // Append both datasets. 00764 00765 // First, iterates slices of 100 records from the source dataset. 00766 global $base_url; 00767 00768 $html .= ' 00769 00770 <script type="text/javascript"> 00771 var progress; // progress element reference 00772 var request; // request object 00773 var request_progress; 00774 var intervalID; // interval ID 00775 var token = Math.random(); 00776 00777 // button actions 00778 function polling_start() {intervalID = window.setInterval(\'send_request()\',1500)} 00779 function polling_init() 00780 { 00781 progress = document.getElementById(\'progress\'); 00782 request_progress = initXMLHttpClient(); 00783 request = initXMLHttpClient(); 00784 00785 send_init_request(); 00786 polling_start(); 00787 } 00788 00789 // create an XMLHttpClient in a cross-browser manner 00790 function initXMLHttpClient(){ 00791 var xmlhttp; 00792 try {xmlhttp=new XMLHttpRequest()} // Mozilla/Safari/IE7 (normal browsers) 00793 catch(e){ // IE (?!) 00794 var success=false; 00795 var XMLHTTP_IDS=new Array(\'MSXML2.XMLHTTP.5.0\',\'MSXML2.XMLHTTP.4.0\', 00796 \'MSXML2.XMLHTTP.3.0\',\'MSXML2.XMLHTTP\',\'Microsoft.XMLHTTP\'); 00797 for (var i=0; i<XMLHTTP_IDS.length && !success; i++) 00798 try {success=true; xmlhttp=new ActiveXObject(XMLHTTP_IDS[i])} catch(e){} 00799 if (!success) throw new Error(\'Unable to create XMLHttpRequest!\'); 00800 } 00801 return xmlhttp; 00802 } 00803 00804 // send request to the server 00805 function send_request(){ 00806 request_progress.open(\'GET\',\''.$base_url.'/'.drupal_get_path('module', 'structAppend').'/progress/progress_\'+token+\'.xml\', true); // open asynchronus request 00807 request_progress.onreadystatechange = request_handler; // set request handler 00808 request_progress.send(null); // send request 00809 } 00810 00811 // send initial request 00812 function send_init_request(){ 00813 request.open(\'GET\',\''.$base_url.'/'.drupal_get_path('module', 'structAppend').'/append.php?token=\'+token+\'&source=\'+escape(\''.$source.'\')+\'&target=\'+escape(\''.$target.'\')+\'&userIP=\'+escape(\''.$userIP.'\'), true); // open asynchronus request 00814 request.onreadystatechange = request_append_handler; // set request handler 00815 request.send(null); // send request 00816 } 00817 00818 var requestDone = 0; 00819 00820 // request handler 00821 function request_handler() 00822 { 00823 if(request_progress.readyState == 4) 00824 { 00825 // if state = 4 (the operation is completed) 00826 if(requestDone == 0) 00827 { 00828 if(request_progress.status == 200) 00829 { 00830 // and the HTTP status is OK 00831 // get progress from the XML node and set progress bar width and innerHTML 00832 var level=request_progress.responseXML.getElementsByTagName(\'PROGRESS\')[0].firstChild; 00833 if(level.nodeValue == "0" || level.nodeValue == "Initializing...") 00834 { 00835 progress.style.width = \'0%\'; 00836 } 00837 else 00838 { 00839 progress.style.width = level.nodeValue + \'%\'; 00840 } 00841 00842 if(level.nodeValue == "0" || level.nodeValue == "Initializing...") 00843 { 00844 document.getElementById("nextStepButton").value = \'Initializing...\'; 00845 } 00846 else 00847 { 00848 document.getElementById("nextStepButton").value = level.nodeValue + \'%\'; 00849 } 00850 00851 document.getElementById("nextStepButton").disabled = true; 00852 } 00853 else 00854 { 00855 if(request_progress.status != 304 && request_progress.status != 404) 00856 { 00857 // if request_progress status is different then 200 00858 progress.style.width = \'100%\'; 00859 //progress.innerHTML=\'Error: [\'+request_progress.status+\'] \'+request_progress.statusText; 00860 document.getElementById("nextStepButton").value=\'Error: [\'+request_progress.status+\'] \'+request_progress.statusText; 00861 document.getElementById("nextStepButton").disabled = true; 00862 } 00863 } 00864 } 00865 } 00866 } 00867 00868 // Append.php handler. It is noticed when the entire progress is done 00869 function request_append_handler() 00870 { 00871 if(request.readyState == 4) 00872 { 00873 requestDone = 1; 00874 00875 // if state = 4 (the operation is completed) 00876 if(request.status == 200) 00877 { 00878 // and the HTTP status is OK 00879 // get progress from the XML node and set progress bar width and innerHTML 00880 progress.style.width = \'100%\'; 00881 progress.innerHTML = \'100% (completed)\'; 00882 document.getElementById("nextStepButton").value = "Next step: delete source dataset (optional)"; 00883 document.getElementById("nextStepButton").disabled = true; 00884 } 00885 else 00886 { 00887 // if request status is different then 200 00888 progress.style.width = \'100%\'; 00889 progress.innerHTML = \'100% (with error)\'; 00890 document.getElementById("nextStepButton").value = "Next step: delete source dataset (optional)"; 00891 document.getElementById("nextStepButton").disabled = true; 00892 00893 alert(\'Error: \'+request.responseText); 00894 } 00895 00896 window.clearInterval(intervalID); 00897 00898 document.getElementById("nextStepButton").disabled = false; 00899 } 00900 } 00901 00902 </script> 00903 00904 <style> 00905 div#progress_container{border:2px double #ccc;width:600px;margin-top:20px;padding:0; text-align:left;} 00906 div#progress{text-align:center;color:#FFF;background-color:#FF8D40;height:12px;padding-bottom:2px;overflow:hidden;line-height:1.2em} 00907 </style> 00908 00909 <center> 00910 <div id="progress_container"> 00911 <div style="width: 0%;" id="progress"></div> 00912 </div> 00913 00914 <br /><br />'; 00915 00916 00917 $html .= "<form action=\"" . $base_url . "/conStruct/append/\" method=\"get\"> 00918 <center> 00919 <table style=\"width: 600px;\"> 00920 <tr> 00921 <td align=\"center\"> 00922 <input name=\"step\" type=\"hidden\" value=\"delete\" /> 00923 <input name=\"source\" type=\"hidden\" value=\"$source\" /> 00924 <input name=\"sourceName\" type=\"hidden\" value=\"$sourceName\" /> 00925 <input name=\"target\" type=\"hidden\" value=\"$target\" /> 00926 <input name=\"targetName\" type=\"hidden\" value=\"$targetName\" /> 00927 <input name=\"userIP\" id=\"userIP\" type=\"hidden\" value=\"$userIP\" /> 00928 <input disabled=\"true\" style=\"width:600px;\" id=\"nextStepButton\" type=\"submit\" value=\"" . t("Initializing...") . "\" /> 00929 </td> 00930 </tr> 00931 </table> 00932 </center> 00933 </form>"; 00934 00935 00936 $html .= ' </center> 00937 00938 <script type="text/javascript"> 00939 polling_init(); 00940 </script> 00941 00942 '; 00943 00944 00945 } 00946 break; 00947 00948 case "delete": 00949 { 00950 $html .= ' 00951 00952 <h1>'.t("Dataset Appending Tool").'</h1> 00953 <br /> 00954 <table style="background-color:#F4F7E7; border:1px solid #537407; 00955 padding:8px; vertical-align:middle;"> 00956 <tr> 00957 <td> 00958 <b>'.t("Steps:").'</b> 00959 </td> 00960 <td> 00961 '.t("1. Set Source Dataset").' 00962 </td> 00963 <td> 00964 '.t("2. Set Target Dataset").' 00965 </td> 00966 <td> 00967 '.t("3. Append Datasets").' 00968 </td> 00969 <td> 00970 '.t("4. Appending...").' 00971 </td> 00972 <td> 00973 <b>'.t("5. Delete Source Dataset (Optional)").'</b> 00974 </td> 00975 00976 </tr> 00977 </table> 00978 <br /><br /> 00979 00980 '.t("The the final step is to optionally delete the source dataset from the system now that 00981 it has been appended to the target dataset.").' 00982 00983 <br /><br /> 00984 '; 00985 00986 $source = explode(" :: ", $source); 00987 $groupID = getGroupIdFromDatasetUri($source[0]); 00988 00989 $html .= "<center><form action=\"" . $base_url . "/node/" . $groupID . "/delete\" method=\"get\"> 00990 <input type=\"submit\" value=\"Delete the '$sourceName' source dataset\" /> 00991 </form>"; 00992 00993 $html .= "<br /><br />— or —<br /><br />"; 00994 00995 $target = explode(" :: ", $target); 00996 00997 $html .= "<form action=\"" . $base_url . "/conStruct/browse/\" method=\"get\"> 00998 <input name=\"browse\" type=\"hidden\" value=\"true\" /> 00999 <input name=\"dataset\" type=\"hidden\" value=\"" . $target[0] . "\" /> 01000 <input type=\"submit\" value=\"Browse the '$targetName' target dataset\" /> 01001 </form></center>"; 01002 01003 01004 } 01005 break; 01006 } 01007 01008 return ($html); 01009 } 01010 } 01011 01012 function getAvailableDatasets() 01013 { 01014 global $user; 01015 01016 $userIP = variable_get("conStruct_AccessUser" . $user->uid, ""); 01017 01018 if ($userIP == "") 01019 { 01020 // If there is no IP for that user, we overload the IP of the node with "::" 01021 $userIP = "self::$user->uid"; 01022 } 01023 01024 // First, we have to iterate over all registered WSF address to get all defined and accessible 01025 // datasets for this user 01026 01027 $wsfRegistry = variable_get("WSF-Registry", ""); 01028 01029 $availableDatasets = array(); 01030 01031 if ($wsfRegistry != "") 01032 { 01033 $includedWsfAddresses = array(); 01034 01035 foreach ($wsfRegistry as $wsfAddress) 01036 { 01037 // Now, lets create the union of all datasets created/linked for that node. We will only query 01038 // them (even if world readable (public) ones can be accessible from a target WSF) 01039 01040 $nodeAvailableDatasets = array(); 01041 01042 $resultset = db_query('SELECT nid FROM {og}'); 01043 01044 $linkedDatasets = variable_get("Linked-Dataset-Registry", array()); 01045 01046 while($datasetId = db_result($resultset)) 01047 { 01048 $datasetWsf = variable_get("Dataset-" . $datasetId . "-WSF", ""); 01049 01050 if($datasetWsf == $wsfAddress) 01051 { 01052 // If this dataset come from this WSF Address, then we include it into the dataset to search for. 01053 01054 // Check if it is a linked dataset 01055 if(isset($linkedDatasets[$datasetId])) 01056 { 01057 array_push($nodeAvailableDatasets, $linkedDatasets[$datasetId]); 01058 } 01059 else 01060 { 01061 global $base_url; 01062 01063 array_push($nodeAvailableDatasets, get_domain($base_url) . "/wsf/datasets/" . $datasetId . "/"); 01064 } 01065 } 01066 } 01067 01068 // Get accessible datasets for this user 01069 $wsq = new WebServiceQuerier($wsfAddress . "dataset/read/", "get", "text/xml", 01070 "uri=all®istered_ip=" . urlencode($userIP), 2); 01071 01072 if ($wsq->getStatus() == 200) 01073 { 01074 // Get all web services 01075 $webservices = ""; 01076 01077 $xml = new ProcessorXML(); 01078 $xml->loadXML($wsq->getResultset()); 01079 01080 $datasets = $xml->getSubjectsByType("void:Dataset"); 01081 01082 foreach ($datasets as $dataset) 01083 { 01084 $datasetUri = $xml->getURI($dataset); 01085 01086 $predicates = $xml->getPredicatesByType($dataset, "dcterms:title"); 01087 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 01088 $datasetTitle = $xml->getContent($objects->item(0)); 01089 01090 // Make sure this dataset is linked to or available to the node 01091 if (array_search($datasetUri, $nodeAvailableDatasets) !== FALSE) 01092 { 01093 array_push($availableDatasets, array( 01094 $datasetUri, 01095 $datasetTitle, 01096 $wsfAddress 01097 )); 01098 } 01099 } 01100 } 01101 else 01102 { 01103 if ($wsq->getStatus() != 503 && $wsq->getStatus() != 404) 01104 { 01105 $wsq->displayError(); 01106 } 01107 } 01108 01109 unset($wsq); 01110 } 01111 } 01112 01113 return($availableDatasets); 01114 } 01115 01117 01118 ?>
