Guest User

Untitled

a guest
Sep 1st, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.19 KB | None | 0 0
  1. function freeway_retrieve($form, &$form_state) {
  2.  
  3.   global $user;
  4.   $arrayForSendTranslation = array();
  5.   $arrayForSendTranslation = credentialProvider();
  6.  
  7.   $finalFunctionUserName = $arrayForSendTranslation[0];
  8.   $finalFunctionPassword = $arrayForSendTranslation[1];
  9.  
  10.  
  11.   $fileIdbtained = $_GET['fileId'];
  12.   $pidobtained = $_GET['projectID'];
  13.   $fileName = $_GET['fileName'];
  14.   $dbArray = array();
  15.  
  16.   $form['freeway_node_types'] = array(
  17.     '#type' => 'checkboxes',
  18.     '#title' => t('Contents which can be considered for Freeway'),
  19.     '#options' => $options,
  20.     '#default_value' => variable_get('freeway_node_types', array('page')),
  21.     '#description' => t('A text field will be available on these content types to make user-specific notes.'),
  22.   );
  23.  
  24. $parts = parse_ini_file('sites/all/modules/freeway/urlconfig.ini');
  25.  
  26.  
  27.  
  28.  
  29.  
  30. $LoginClient = new SoapClient($parts['part1'], array("trace" => 1));
  31.  
  32. $ServicesLink = new SoapClient($parts['part2'], array("trace" => 1));
  33.   //Clean extracted folder
  34.  
  35.   $structurePreCleanExtracted = dirname(__FILE__) . '/extracted/';
  36.   if (is_dir($structurePreCleanExtracted)) {
  37.  
  38.     removedir(dirname(__FILE__) . '/extracted/');
  39.   }
  40.  
  41.  
  42.  
  43.   try {
  44.  
  45.     $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
  46.     $ticket = ($arrResponse->LogonResult);
  47.     $fileRetrieve = $ServicesLink->RetrieveProjectFileByID(array('Ticket' => $ticket, 'ProjectID' => $pidobtained, 'FileID' => $fileIdbtained));
  48.     $resultFile = $fileRetrieve->RetrieveProjectFileByIDResult;
  49.     $ourFileName = $fileName;
  50.  
  51.  
  52.     $ourFileHandle = fopen($ourFileName, 'w') or ("can't open file");
  53.     fclose($ourFileHandle);
  54.  
  55.     $fp = fopen($fileName, 'w');
  56.     fwrite($fp, $resultFile);
  57.     fclose($fp);
  58.  
  59.  
  60.     $zip = new ZipArchive;
  61.    
  62.  
  63.     if ($zip->open($ourFileName)) {
  64.       for ($i = 0; $i < $zip->numFiles; $i++) {
  65.  
  66.       }
  67.       if ($zip->extractTo(dirname(__FILE__) . '/extracted/')) {
  68.  
  69.       }
  70.       else {
  71.  
  72.         drupal_get_messages();
  73.         drupal_set_message("ERROR IN FILE EXTRACTING!");
  74.         drupal_goto("user");
  75.  
  76.       }
  77.       $zip->close();
  78.     }
  79.     else {
  80.       echo drupal_get_messages();
  81.       drupal_set_message("Error reading zip-archive!");
  82.       drupal_goto("user");
  83.  
  84.     }
  85.  
  86.     $dirlist = getFileListDash(dirname(__FILE__) . '/extracted/');
  87.     for ($i = 0; $i < count($dirlist); $i += 1) {
  88.       $xml = simplexml_load_file($dirlist[$i]);
  89.       $nodeID = $xml->NodeId;
  90.       $src_Lang = $xml->SrcLang;
  91.       $tar_Lang = $xml->TarLang;
  92.       $node_title = $xml->NodeTitle;
  93.       $node_body = $xml->NodeBody;
  94.  
  95.       $resultFileID = db_query("SELECT *  FROM {freeway_fileid} where freeway_file_id = '$fileIdbtained'");
  96.       $rowsFileID = $resultFileID->rowCount();  
  97.  
  98.    if ($rowsFileID == 0) {
  99.         drupal_get_messages();
  100.         drupal_set_message("This content was not sent out from the current Drupal Connector setup. Hence cannot be retrieved!");
  101.  
  102.         unlink('./' . $ourFileName);
  103.         removedir(dirname(__FILE__) . '/extracted/');
  104.  
  105.         drupal_goto('user/' . $user->uid . '/freewayDashboard');
  106.       }
  107.       else {
  108.      
  109.  
  110.         foreach($resultFileID as $recordFileID )
  111.  
  112.         {
  113.           $fileIdFromTable = $recordFileID->freeway_file_id;
  114.           $first = $recordFileID->freeway_tar_lang;
  115.         }
  116.  
  117.       }
  118.  
  119.       $result = db_query("SELECT * FROM {freeway}
  120.  
  121.                      WHERE node_id = '$nodeID'
  122.  
  123.                      AND src_lang ='$src_Lang'
  124.  
  125.                      AND tar_lang='$first'
  126.  
  127.                      AND project_id ='$pidobtained'");
  128.  
  129.                      
  130.      
  131.  
  132.       $record = db_query("SELECT * FROM {freeway}
  133.  
  134.                      WHERE node_id = '$nodeID'
  135.  
  136.                      AND src_lang ='$src_Lang'
  137.  
  138.                      AND tar_lang='$first'
  139.  
  140.                      AND project_id ='$pidobtained'")->fetchObject();
  141.  
  142.  
  143.  
  144.      
  145.  
  146.         foreach($result as $recordUI )
  147.  
  148.       {
  149.         $serial_id = $recordUI->sr_id;
  150.  
  151.         if (strlen($serial_id)) {
  152.          
  153.           db_query("UPDATE {freeway} SET node_id ='$nodeID',file_id ='$fileIdbtained',project_id='$pidobtained',src_lang = '$src_Lang',tar_lang='$first',node_title='$node_title',node_body='$node_body' WHERE sr_id='$serial_id'");
  154.         }
  155.         else {
  156.  
  157.          
  158.           db_query("INSERT INTO {freeway} (node_id, file_id,project_id,src_lang, tar_lang, node_title, node_body) VALUES ('$nodeID','$fileIdbtained','$pidobtained','$src_Lang','$first','$node_title','$node_body')");
  159.         }
  160.  
  161.       }
  162.       if (!$record) {
  163.  
  164.        
  165.         db_query("INSERT INTO {freeway} (node_id, file_id,project_id,src_lang, tar_lang, node_title, node_body) VALUES ('$nodeID','$fileIdbtained','$pidobtained','$src_Lang','$first','$node_title','$node_body')");
  166.  
  167.       }
  168.  
  169.     }
  170.  
  171.    
  172.  
  173.     rrmdir_a(dirname(__FILE__) . '/extracted/');
  174.     unlink('./' . $ourFileName);
  175.  
  176.  
  177.  
  178.   }
  179.  
  180.   catch (SoapFault $exception) {
  181.     drupal_get_messages();
  182.     drupal_set_message("The following exception took place." . $exception . "Kindly check Freeway mapping");
  183.     drupal_goto("user");
  184.  
  185.  
  186.  
  187.   }
  188.   drupal_get_messages();
  189.   drupal_set_message(" Available files for the  project " . $pidobtained . " have been retrieved into Drupal Database");
  190.   drupal_goto('user/' . $user->uid . '/freewayDashboard');
  191.  
  192.   return $form;
  193.  
  194. }
Add Comment
Please, Sign In to add comment