DrupalCustom

newRewamp

Feb 17th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.32 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5.  * @todo Please document this function.
  6.  * @see http://drupal.org/node/1354
  7.  */
  8. function formModifications_menu() {
  9.  
  10.   $items['translate/bulk'] = array(
  11.     'title' => t('Send Multiple Contents'),
  12.     'description' => t('Translate multiple nodes'),
  13.     'page callback' => 'drupal_get_form',
  14.     'page arguments' => array('formModifications_translate_bulk'),
  15.     'access arguments' => array('access translator'),
  16.   );
  17.  
  18.   return $items;
  19. }
  20.  
  21.  
  22. /**
  23.  * @todo Please document this function.
  24.  * @see http://drupal.org/node/1354
  25.  */
  26. function formModifications_translate_bulk($form, &$form_state) {
  27.   global $user;
  28.   global $finalFunctionUserName;
  29.   global $finalFunctionPassword;
  30.  
  31.   $arrayForSendTranslation = array();
  32.   $arrayForSendTranslation = formModCredentialProvider();
  33.  
  34.   $finalFunctionUserName = $arrayForSendTranslation[0];
  35.   $finalFunctionPassword = $arrayForSendTranslation[1];
  36.  
  37.  
  38.  
  39.  // drupal_add_js(drupal_get_path('module', 'formModifications') . '/js/script.js');
  40.   // Get the nodes.
  41.   $chosenContents = "Contents Chosen :";
  42.   $nodes_ser = trim($_GET['nodes']);
  43.   $nodes = explode("-", $nodes_ser);
  44.   $form = array();
  45.   $tarLangId = "Langs:";
  46.  
  47.  
  48.   foreach ( $nodes as $key => $value) {
  49.     $node = node_load($value);
  50.     $chosenContents .= $node->title . " , ";
  51.   }
  52.  
  53.   $finalString = rtrim($chosenContents, ' , ');
  54.  
  55.  
  56.   $form['content_information'] = array(
  57.     '#value' => variable_get('content_form_information', $finalString),
  58.   );
  59.  
  60.  
  61.   $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace" => 1));
  62.   $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace" => 1));
  63.  
  64.  
  65.   try {
  66.  
  67.     $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
  68.  
  69.     $ticket = ($arrResponse->LogonResult);
  70.     $getSrcLang = $ServicesLink->GetSourceLanguages(array('Ticket' => $ticket));
  71.     $getDraftProjectIds = $ServicesLink->GetProjectSummariesList(array('Ticket' => $ticket, 'NumberOfProjects' => 100, 'SortOrder' => MostRecent, 'ProjectStatusCode' => 'Draft'));
  72.  
  73.     $array = array();
  74.     $arrayT = array();
  75.     $forTarLang = array();
  76.     $listOfProjects = array();
  77.     $hopeArray = array();
  78.  
  79.     foreach ($getSrcLang->GetSourceLanguagesResult->Languages->Language as $language) {
  80.       $array[$language->ID] = $language->Description . "_" . $language->ID;
  81.       $forTarLang[] = $language->ID;
  82.     }
  83.  
  84.  
  85.     foreach ($getDraftProjectIds->GetProjectSummariesListResult->ProjectSummaries->ProjectSummary as $projectSummary) {
  86.       $listOfProjects[$projectSummary->ID] = $projectSummary->ID;
  87.     }
  88.  
  89.  
  90.  
  91.   }
  92.   catch (SoapFault $exception) {
  93.     drupal_get_messages();
  94.     drupal_set_message("The following exception took place." . $exception . "Kindly check Freeway mapping");
  95.     drupal_goto("user");
  96.  
  97.  
  98.   }
  99.  
  100.   try {
  101.  
  102.     if (count($forTarLang) != 0) {
  103.       $getTarLang = $ServicesLink->GetTargetLanguages(array('Ticket' => $ticket, 'SourceLanguageID' => $forTarLang[0]));
  104.  
  105.       foreach ($getTarLang->GetTargetLanguagesResult->Languages->Language as $languageT) {
  106.         //$arrayT[$languageT->ID] = $languageT->Description;
  107.         $arrayT[$languageT->ID] = $languageT->Description . "_" . $languageT->ID;
  108.       }
  109.     }
  110.   }
  111.   catch (Exception  $exception1) {
  112.     drupal_get_messages();
  113.     drupal_set_message("The following exception took place." . $exception1);
  114.     drupal_goto("user");
  115.  
  116.   }
  117.  
  118.  
  119.  $options_first = _ajax_example_get_first_dropdown_options_lang();
  120.  
  121.     $selected = isset($form_state['values']['folks_list']) ? $form_state['values']['folks_list'] : key($options_first);
  122.  
  123.   $form['folks_list'] = array(
  124.     '#type' => 'select',
  125.     '#title' => t('Freeway Source Languages New'),
  126.     '#options' => $options_first,
  127.     '#default_value' => $selected,
  128.     '#ajax' => array(
  129.       'callback' => 'ajax_example_dependent_dropdown_callback_lang',
  130.       'wrapper' => 'webDelegate-list-replace',
  131.     ),
  132.   );
  133.  
  134.  
  135.   $currUser = $user->name;
  136.   $hidden_id = "hidden_id";
  137.   $form['bid'] = array(
  138.     '#type' => 'hidden',
  139.     '#value' => $currUser,
  140.     '#attributes' => array('id' => $hidden_id)
  141.  
  142.   );
  143.  
  144.  
  145.  
  146.     $form['webDelegate_list'] = array(
  147.     '#type' => 'select',
  148.     '#title' => $options_first[$selected] . ' ' . t('Freeway Target Languages'),
  149.      '#multiple' => true,
  150.     '#prefix' => '<div id="webDelegate-list-replace">',
  151.     '#suffix' => '</div>',
  152.     '#options' => _ajax_example_get_second_dropdown_options_langs($selected),
  153.     '#default_value' => isset($form_state['values']['webDelegate_list']) ? $form_state['values']['webDelegate_list'] : '',
  154.   );
  155.  
  156.  
  157.  
  158.  
  159.  
  160.   $form['projectId'] = array(
  161.     '#type' => 'select',
  162.     '#title' => t('List of Draft projects created by you.'),
  163.     '#weight' => 9,
  164.     '#options' => $listOfProjects,
  165.   );
  166.  
  167.   $form['translate_node'] = array(
  168.     '#type' => 'submit',
  169.     '#value' => 'Send To Freeway',
  170.     '#weight' => 10,
  171.   );
  172.  
  173.  
  174.  
  175.   return $form;
  176.  
  177. }
  178.  
  179.  
  180. function _ajax_example_get_first_dropdown_options_lang() {
  181.  
  182.   global $finalFunctionUserName;
  183.   global $finalFunctionPassword;
  184.  
  185.   $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace" => 1));
  186.   $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace" => 1));
  187.  
  188.   try {
  189.     $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
  190.  
  191.     $ticket = ($arrResponse->LogonResult);
  192.     $getSrcLang = $ServicesLink->GetSourceLanguages(array('Ticket' => $ticket));
  193.  
  194.     //$array has the list of source languages.
  195.     $array = array();
  196.     $forTarLang = array();
  197.    
  198.     foreach ($getSrcLang->GetSourceLanguagesResult->Languages->Language as $language) {
  199.       $array[$language->ID] = $language->Description . "_" . $language->ID;
  200.       $forTarLang[] = $language->ID;
  201.     }
  202.  
  203.   }
  204.   catch (SoapFault $exception) {
  205.     drupal_get_messages();
  206.     drupal_set_message("The following exception took place in function!." . $exception . "Kindly check Freeway mapping");
  207.     drupal_goto("user");
  208.  
  209.  
  210.   }
  211.    
  212.   return drupal_map_assoc($array);
  213.  
  214.  
  215.  
  216.  
  217. }
  218.  
  219.  
  220. function ajax_example_dependent_dropdown_callback_lang($form, $form_state) {
  221.   return $form['webDelegate_list'];
  222. }
  223.  
  224.  
  225. function _ajax_example_get_second_dropdown_options_langs($key = ''){
  226.  
  227.   global $finalFunctionUserName;
  228.   global $finalFunctionPassword;
  229.  
  230.   $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace" => 1));
  231.   $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace" => 1));
  232.  
  233.   try {
  234.     $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
  235.  
  236.     $ticket = ($arrResponse->LogonResult);
  237.     $getSrcLang = $ServicesLink->GetSourceLanguages(array('Ticket' => $ticket));
  238.  
  239.     //$array has the list of source languages.
  240.     $array = array();
  241.     $arrayTarget = array();
  242.     $forTarLang = array();
  243.    
  244.     foreach ($getSrcLang->GetSourceLanguagesResult->Languages->Language as $language) {
  245.       $array[$language->ID] = $language->Description . "_" . $language->ID;
  246.       $forTarLang[] = $language->ID;
  247.     }
  248.    
  249.  
  250.    
  251.  
  252.   }
  253.   catch (SoapFault $exception) {
  254.     drupal_get_messages();
  255.     drupal_set_message("The following exception took place.1" . $exception . "Kindly check Freeway mapping");
  256.     drupal_goto("user");
  257.  
  258.  
  259.   }
  260.  
  261.    try {
  262.    
  263.    for($p=0;$p< count($array);$p+=1){
  264.     if (count($forTarLang) != 0) {
  265.       $getTarLang = $ServicesLink->GetTargetLanguages(array('Ticket' => $ticket, 'SourceLanguageID' => $forTarLang[$p]));
  266.      
  267.  
  268.       foreach ($getTarLang->GetTargetLanguagesResult->Languages->Language as $languageT) {
  269.         $arrayTarget[$languageT->ID] = $languageT->Description . "_" . $languageT->ID;
  270.         }
  271.        
  272.         $options = array(
  273.     t($array[$p]) => drupal_map_assoc($arrayTarget),
  274.  
  275.   );
  276.        
  277.                
  278.       }
  279.     }
  280.    
  281.   }
  282.   catch (Exception  $exception1) {
  283.     drupal_get_messages();
  284.     drupal_set_message("The following exception took place.2" . $exception1);
  285.     drupal_goto("user");
  286.  
  287.   }
  288.  
  289.  
  290.  
  291.  
  292.   if (isset($options[$key])) {
  293.     return $options[$key];
  294.   }
  295.   else {
  296.     return array();
  297.   }
  298.  
  299. }
  300.  
  301.  
  302.  
  303.  
  304.  
  305. /**
  306.  * @todo Please document this function.
  307.  * @see http://drupal.org/node/1354
  308.  */
  309. function formModifications_translate_bulk_submit($form, &$form_state) {
  310.   global $base_root;
  311.  
  312.   $arrayForSendTranslation = array();
  313.   $arrayForSendTranslation = formModCredentialProvider();
  314.  
  315.   $finalFunctionUserName = $arrayForSendTranslation[0];
  316.   $finalFunctionPassword = $arrayForSendTranslation[1];
  317.  
  318.  
  319.  
  320.  
  321.   $targetLangs = array();
  322.   $finalTarArray = array();
  323.   $zipName = "Content";
  324.   $targetLangNames = '';
  325.   // Obtain Src Lang,TargetLanguage(s) and Project ID inside this function.
  326.   $projectID = isset($form_state['values']['projectId']) ? $form_state['values']['projectId'] : key($options_first);
  327.   $srcLang = isset($form_state['values']['folks_list']) ? $form_state['values']['folks_list'] : key($options_first);
  328. $targetLangs = isset($form_state['values']['webDelegate_list']) ? $form_state['values']['webDelegate_list'] : key($options_first);
  329.  
  330.  
  331.  
  332.   if (count($targetLangs) == 0) {
  333.     drupal_get_messages();
  334.     drupal_set_message("Please select appropriate Freeway Target Languages.");
  335.     drupal_goto($base_root . request_uri());
  336.  
  337.   }
  338.  
  339.  
  340.   foreach ($targetLangs as $langs) {
  341.     list($name, $tarId) = split('[_]', $langs);
  342.     $finalTarArray[] = $tarId;
  343.   }
  344.  
  345.  
  346.  
  347.   // Block to Add task:// Add task to he project - can be hardcoded,Add File and submit.
  348.   $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace" => 1));
  349.   $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace" => 1));
  350.  
  351.  
  352.   if ($handle = opendir('./')) {
  353.     while (false !== ($entry = readdir($handle))) {
  354.       if (substr($entry, -3) == "zip") {
  355.         $fileName = $entry;
  356.       }
  357.     }
  358.     //echo("FileName > ".$fileName);
  359.     //echo('<br>');
  360.     closedir($handle);
  361.  
  362.   }
  363.  
  364.   try {
  365.     $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
  366.     $ticket = ($arrResponse->LogonResult);
  367.  
  368.                 drupal_get_messages();
  369.             drupal_set_message("Here ".$finalTarArray[0].">as>".$finalTarArray[1].">Count>".count($finalTarArray));
  370.             drupal_goto("user");
  371.    
  372.    
  373.  
  374.     for ($j = 0; $j < count($finalTarArray); $j += 1) {
  375.       $addTask = $ServicesLink->AddTaskToProject(array('Ticket' => $ticket, 'ProjectID' => $projectID, 'SourceLanguageID' => $srcLang, 'TargetLanguageID' => $finalTarArray[$j], 'ComponentID' => '', 'SubjectID' => '', 'TaskID' => 'LP', 'SubTaskID' => 'New Words', 'Volume' => '1', 'UOMID' => 'Word'));
  376.  
  377.  
  378.     }
  379.  
  380.  
  381.     for ($t = 0; $t < count($finalTarArray); $t += 1) {
  382.  
  383.       $targetLangNames = $targetLangNames . $finalTarArray[$t] . ',';
  384.  
  385.     }
  386.     $interString = rtrim($targetLangNames, ',');
  387.     $finalString = rtrim($interString, ',');
  388.  
  389.     $structureTemp = './sites/all/tempfolder/';
  390.     $listInTemp = getFileList($structureTemp);
  391.  
  392.     for ($v = 0; $v < count($listInTemp); $v += 1) {
  393.       $content = simplexml_load_file($listInTemp[$v]);
  394.       $content->TarLang = $finalString;
  395.       $content->SrcLang = $srcLang;
  396.       $content->asXML($listInTemp[$v]);
  397.     }
  398.  
  399.  
  400.     $finalZipName = "DrupalContent.zip";
  401.     Zip('./sites/all/tempfolder', './' . $finalZipName);
  402.  
  403.     $handle = fopen("./" . $finalZipName, "r");
  404.     $contents = fread($handle, filesize("./" . $finalZipName));
  405.     fclose($handle);
  406.  
  407.     $addFile = $ServicesLink->AddFileToProject(array('Ticket' => $ticket, 'ProjectID' => $projectID, 'Filename' => $finalZipName, 'FileData' => $contents, 'SourceLanguageID' => $srcLang, 'TargetLanguageIDs' => $finalTarArray, 'Metadata' => null, 'IsReferenceMaterial' => false));
  408.  
  409.     $fileinfoArray = array();
  410.     foreach ($addFile->AddFileToProjectResult->FileInfoItems->FileInfo as $fileInfo) {
  411.       $fileinfoArray[] = $fileInfo;
  412.     }
  413.  
  414.     $bottomFileId = $fileinfoArray[0];
  415.     $topFileId = ($bottomFileId - (count($finalTarArray) -1));
  416.     for ($e = 0; $e < count($finalTarArray); $e += 1) {
  417.  
  418.       // TODO Please convert this statement to the D7 database API syntax.
  419.       db_query("INSERT INTO {freeway_fileid} (freeway_file_id, freeway_tar_lang) VALUES ('$topFileId','$finalTarArray[$e]')");
  420.       $topFileId += 1;
  421.  
  422.     }
  423.     $topFileId = 0;
  424.  
  425.     $submitProject = $ServicesLink->SubmitProject(array('Ticket' => $ticket, 'ProjectID' => $projectID));
  426.  
  427.  
  428.   }
  429.  
  430.  
  431.  
  432.   catch (SoapFault $exception) {
  433.     drupal_get_messages();
  434.     drupal_set_message("The following exception took place." . $exception . "Kindly check Freeway mapping");
  435.     drupal_goto("user");
  436. //  return $exception;
  437.   }
  438.  
  439.   // End of Block to add task.
  440.  
  441.  
  442.   //Block for deletion of zip and tempfolder.
  443.  
  444.   unlink('./' . $finalZipName);
  445.   rrmdir('./sites/all/tempfolder');
  446.   // End of Block for Deletions.
  447.  
  448.  
  449.   drupal_get_messages();
  450.   drupal_set_message("Project with project ID " . $projectID . " submitted to Freeway");
  451.   drupal_goto("user");
  452.   //    drupal_goto("admin/config/freeway");
  453.  
  454. }
  455.  
  456.  
  457.  
  458. /**
  459.  * @todo Please document this function.
  460.  * @see http://drupal.org/node/1354
  461.  */
  462. function formModifications_form_alter(&$form, &$form_state, $form_id) {
  463.  
  464.   if ($form_id == 'node_admin_content') {
  465.     $form['admin']['options']['operation']['#options']['send_for_translation'] = t('Send For Translation');
  466.     $form['admin']['options']['submit']['#submit'][] = 'custom_send_for_translation_submit_admin';
  467.   }
  468. }
  469.  
  470. function custom_send_for_translation_submit_admin($form, &$form_state) {
  471.   $zipName = "Content";
  472.   $nodes = array();
  473.   $structurePreClean = './sites/all/tempfolder/';
  474.   if (is_dir($structurePreClean)) {
  475.     rrmdir('./sites/all/tempfolder');
  476.   }
  477.  
  478.  
  479.  
  480.   foreach ($form_state['values']['nodes'] as $key => $value) {
  481.     if ($value != 0) {
  482.       $selected[] = node_load($key);
  483.     }
  484.  
  485.   }
  486.  
  487.   if (count($selected) == 0) {
  488.     drupal_get_messages();
  489.     drupal_set_message("No contents selected!");
  490.     drupal_goto('admin/content/node');
  491.  
  492.   }
  493.  
  494.  
  495.  
  496.   foreach ($selected as $key => $value ) {
  497.     $structure = './sites/all/tempfolder/';
  498.  
  499.  
  500.     if (!is_dir($structure)) {
  501.       mkdir($structure, 0, true);
  502.     }
  503.     //Added jan19,2012
  504.     /*
  505.      else{
  506.      rrmdir('./sites/all/tempfolder');
  507.  
  508.      }
  509.      */
  510.     $fileName = $value->title;
  511.     $sPattern = '/\s*/m';
  512.     $sReplace = '';
  513.     $refinedFileName = preg_replace( $sPattern, $sReplace, $fileName ) . ".xml";
  514.     $finalRefinedFileName = $structure . $refinedFileName;
  515.     $ourFileHandle = fopen($finalRefinedFileName, 'w') or ("can't open file");
  516.     $stringXmlHead = '<?xml version="1.0"?>' . "\r\n";
  517.     fwrite($ourFileHandle, $stringXmlHead);
  518.     $rootNode = "<DrupalConnector>" . "\r\n";
  519.     fwrite($ourFileHandle, $rootNode);
  520.  
  521.     $nodeIdTagStart = "<NodeId>";
  522.     fwrite($ourFileHandle, $nodeIdTagStart);
  523.     $nodeId = $value->nid;
  524.     fwrite($ourFileHandle, $nodeId);
  525.     $nodeIdTagEnd = "</NodeId>" . "\r\n";
  526.     fwrite($ourFileHandle, $nodeIdTagEnd);
  527.  
  528.     $drupalVerTagStart = "<DrupalVer>";
  529.     fwrite($ourFileHandle, $drupalVerTagStart);
  530.     $drupalVer = '6.0';
  531.     fwrite($ourFileHandle, $drupalVer);
  532.     $drupalVerTagEnd = "</DrupalVer>" . "\r\n";
  533.     fwrite($ourFileHandle, $drupalVerTagEnd);
  534.  
  535.     $connectorVerTagStart = "<ConnectorVer>";
  536.     fwrite($ourFileHandle, $connectorVerTagStart);
  537.     $conectorVer = '1.0';
  538.     fwrite($ourFileHandle, $conectorVer);
  539.     $connectorVerTagEnd = "</ConnectorVer>" . "\r\n";
  540.     fwrite($ourFileHandle, $connectorVerTagEnd);
  541.  
  542.  
  543.     $srcLangTagStart = "<SrcLang>";
  544.     fwrite($ourFileHandle, $srcLangTagStart);
  545.     $srcLang = '';
  546.     fwrite($ourFileHandle, $srcLang);
  547.     $srcLangTagEnd = "</SrcLang>" . "\r\n";
  548.     fwrite($ourFileHandle, $srcLangTagEnd);
  549.  
  550.     $tarLangTagStart = "<TarLang>";
  551.     fwrite($ourFileHandle, $tarLangTagStart);
  552.     $tarLang = '';
  553.     fwrite($ourFileHandle, $tarLang);
  554.     $tarLangTagEnd = "</TarLang>" . "\r\n";
  555.     fwrite($ourFileHandle, $tarLangTagEnd);
  556.  
  557.     $timeTagStart = "<TimeOfSend>";
  558.     fwrite($ourFileHandle, $timeTagStart);
  559.     $time = date("Y-m-d H:i:s");
  560.     fwrite($ourFileHandle, $time);
  561.     $timeTagEnd = "</TimeOfSend>" . "\r\n";
  562.     fwrite($ourFileHandle, $timeTagEnd);
  563.  
  564.  
  565.     $nodeTitleTagStart = "<NodeTitle>";
  566.     fwrite($ourFileHandle, $nodeTitleTagStart);
  567.     $nodeTitle = "<![CDATA[" . $value->title . "]]>";
  568.     fwrite($ourFileHandle, $nodeTitle);
  569.     $nodeTitleTagEnd = "</NodeTitle>" . "\r\n";
  570.     fwrite($ourFileHandle, $nodeTitleTagEnd);
  571.     $nodeBodyTagStart = "<NodeBody>";
  572.     fwrite($ourFileHandle, $nodeBodyTagStart);
  573.     $nodeBody = "<![CDATA[" . $value->body . "]]>";
  574.     fwrite($ourFileHandle, $nodeBody);
  575.     $nodeBodyTagEnd = "</NodeBody>" . "\r\n";
  576.     fwrite($ourFileHandle, $nodeBodyTagEnd);
  577.     $rootNodeEnd = "</DrupalConnector>" . "\r\n";
  578.     fwrite($ourFileHandle, $rootNodeEnd);
  579.  
  580.     $zipName .= "_" . $nodeId;
  581.  
  582.  
  583.     $nodes[] = $value->nid;
  584.   }
  585.   fclose($ourFileHandle);
  586.  
  587.   $finalZipName = $zipName . ".zip";
  588.  
  589.   // Zip('./sites/all/tempfolder','./'.$finalZipName);
  590.   //zipping done
  591.   $nodes_ser = implode('-', $nodes);
  592.  
  593.   /*
  594.             drupal_get_messages();
  595.             drupal_set_message("Here ".$nodes_ser."as");
  596.             drupal_goto("user");
  597.   */
  598.  
  599.  
  600.   //drupal_goto('translate/bulk', array('query' => array('nodes' => '\' . $nodes_ser')));
  601.    //drupal_goto('translate/bulk', 'nodes='. $nodes_ser);
  602.    drupal_goto('translate/bulk', array('query' => array('nodes' => $nodes_ser)));
  603.  
  604. }
  605.  
  606.  
  607. function Zip($source, $destination) {
  608.   if (!extension_loaded('zip') || !file_exists($source)) {
  609.     return false;
  610.   }
  611.  
  612.   $zip = new ZipArchive();
  613.   if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
  614.     return false;
  615.   }
  616.  
  617.   $source = str_replace('\\', '/', realpath($source));
  618.   if (is_dir($source) === true) {
  619.     $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
  620.     foreach ($files as $file) {
  621.       $file = str_replace('\\', '/', realpath($file));
  622.       if (is_dir($file) === true) {
  623.         $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
  624.       }
  625.       else if (is_file($file) === true) {
  626.         $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
  627.       }
  628.     }
  629.   }
  630.  
  631.   else if (is_file($source) === true) {
  632.     $zip->addFromString(basename($source), file_get_contents($source));
  633.   }
  634.   return $zip->close();
  635. }
  636.  
  637.  
  638. function rrmdir($dir) {
  639.   if (is_dir($dir)) {
  640.     $objects = scandir($dir);
  641.     foreach ($objects as $object) {
  642.       if ($object != "." && $object != "..") {
  643.         if (filetype($dir . "/" . $object) == "dir") {
  644.           rrmdir($dir . "/" . $object);
  645.         }
  646.         else {
  647.           unlink($dir . "/" . $object);
  648.         }
  649.       }
  650.     }
  651.     reset($objects);
  652.     rmdir($dir);
  653.   }
  654. }
  655.  
  656. function getFileList($dir) {
  657.   // array to hold return value
  658.   $retval = array();
  659.  
  660.   // add trailing slash if missing
  661.   if (substr($dir, -1) != "/") {
  662.     $dir .= "/";
  663.   }
  664.  
  665.   // open pointer to directory and read list of files
  666.   $d = @dir($dir) or ("getFileList: Failed opening directory $dir for reading");
  667.   while (false !== ($entry = $d->read())) {
  668.     // skip hidden files
  669.     if ($entry[0] == ".") {
  670.       continue;
  671.     }
  672.     if (!is_dir("$dir$entry") && is_readable("$dir$entry")) {
  673.       $retval[] = "$dir$entry";
  674.     }
  675.   }
  676.   $d->close();
  677.  
  678.   return $retval;
  679. }
  680.  
  681.  
  682.  
  683.  
  684. function formModCredentialProvider() {
  685.  
  686.   $arrayWithCredentials = array();
  687.   global $user;
  688.   /*
  689.  
  690.    1.Get the current mode.
  691.    1.1. If curr mode = 0 ;
  692.    Navigate to a page saying "Kindly use user mapping options to provide Freeway Credentials"
  693.    1.2  If curr mode = 1 ;
  694.    Select freeway uname and pwrd from global table and set them to the variables.
  695.    if uname = '' or pwrd = '' ; -> navigate to page saying "The Freway credentials have not been entered
  696.    correctly in tha mapping page"
  697.    else set the variable with the value obtained.
  698.  
  699.    1.3      else if curr mode = 2;
  700.    Get currently logged in user name.
  701.    Select freeway uname and pwrd from non global table where drupal username = 'currently logged in user name'
  702.    if uname = '' or pwrd = '' ; -> navigate to page saying "The Freway credentials have not been entered
  703.    correctly in tha mapping page"
  704.    else set the variable with the value obtained.
  705.  
  706.    */
  707.  
  708.   $resultUsPw = db_query("SELECT mode_id FROM {freeway_mode} where sr_id = 1");
  709. //  $rowsUsPw = mysql_num_rows($resultUsPw);
  710.   $rowsUsPw = $resultUsPw->rowCount();
  711.  
  712.   if ($rowsUsPw == 0) {
  713.     drupal_get_messages();
  714.     drupal_set_message("The Freeway user mapping for Drupal users has not been completed. Kindly associate
  715.         Drupal users with Freeway credentials");
  716.     drupal_goto('user/' . $user->uid . '/freewayUserMapping');
  717.   }
  718.  
  719.   else {
  720.     //while ($recordUsPw  = db_fetch_object($resultUsPw))
  721.     foreach($resultUsPw as $recordUsPw )
  722.     {
  723.       $modeValueUsPw = $recordUsPw->mode_id;
  724.     }
  725.  
  726.     if ($modeValueUsPw == '0') {
  727.       drupal_get_messages();
  728.       drupal_set_message("Kindly use user mapping options to provide Freeway Credentials");
  729.       drupal_goto('user/' . $user->uid . '/freewayUserMapping');
  730.     }
  731.     else if ($modeValueUsPw == '1') {
  732.  
  733.       $globalResult = db_query("SELECT freeway_global_username,freeway_global_password FROM {freeway_global_user} where sr_id = 1");
  734.       //$rowsGlobalUsPw = mysql_num_rows($globalResult);
  735.      
  736.       $rowsGlobalUsPw = $globalResult->rowCount();
  737.       if ($rowsGlobalUsPw == 0) {
  738.         drupal_get_messages();
  739.         drupal_set_message("There is no Freeway credential mapped for the Global user role logged ");
  740.         drupal_goto('user/' . $user->uid . '/freewayGlobalUser');
  741.       }
  742.       else {
  743. //        while ($recordUsPwGl  = db_fetch_object($globalResult))
  744.         foreach($globalResult as $recordUsPwGl)
  745.         {
  746.           $freewayGlobalUserName = $recordUsPwGl->freeway_global_username;
  747.           $freewayGlobalPassword = $recordUsPwGl->freeway_global_password;
  748.  
  749.           if ((strlen($freewayGlobalUserName) == '0') || (strlen($freewayGlobalPassword) == '0')) {
  750.             drupal_get_messages();
  751.             drupal_set_message("Kindly use user mapping options to provide Freeway Credentials for the Global user");
  752.             drupal_goto('user/' . $user->uid . '/freewayGlobalUser');
  753.           }
  754.           else {
  755.             $finalUserName = $freewayGlobalUserName;
  756.             $finalPassword = $freewayGlobalPassword;
  757.           }
  758.  
  759.         }
  760.       }
  761.     }
  762.  
  763.     else if ($modeValueUsPw == '2') {
  764.       $userNameCurr = $user->name;
  765.       // TODO Please convert this statement to the D7 database API syntax.
  766.       $nonGlobalResult = db_query("SELECT freeway_username ,freeway_password  FROM {freeway_users} where drupal_username = '$userNameCurr'");
  767.  
  768.     //  $rowsNonGlobalUsPw = mysql_num_rows($nonGlobalResult);
  769.         $rowsNonGlobalUsPw = $nonGlobalResult->rowCount();
  770.      
  771.       if ($rowsNonGlobalUsPw == 0) {
  772.         drupal_get_messages();
  773.         drupal_set_message("There are no Freeway credentials mapped for the currently logged in user " . $userNameCurr . ".");
  774.         drupal_goto('user/' . $user->uid . '/freewayNonGlobalUser');
  775.       }
  776.       else {
  777.         //while ($recordUsPwNonGl  = db_fetch_object($nonGlobalResult))
  778.         foreach ($nonGlobalResult as $recordUsPwNonGl )
  779.         {
  780.           $freewayNonGlobalUserName = $recordUsPwNonGl->freeway_username;
  781.           $freewayNonGlobalPassword = $recordUsPwNonGl->freeway_password;
  782.  
  783.           if ((strlen($freewayNonGlobalUserName) == '0') || (strlen($freewayNonGlobalPassword) == '0')) {
  784.             drupal_get_messages();
  785.             drupal_set_message("There are no Freeway credentials mapped for the currently logged in user " . $userNameCurr . ".");
  786.             drupal_goto('user/' . $user->uid . '/freewayNonGlobalUser');
  787.           }
  788.           else {
  789.             $finalUserName = $freewayNonGlobalUserName;
  790.             $finalPassword = $freewayNonGlobalPassword;
  791.  
  792.           }
  793.         }
  794.  
  795.       }
  796.  
  797.     }
  798.  
  799.  
  800.  
  801.  
  802.   }
  803.  
  804.   $arrayWithCredentials[0] = $finalUserName;
  805.   $arrayWithCredentials[1] = $finalPassword;
  806.  
  807.   return $arrayWithCredentials;
  808.  
  809. }
Advertisement
Add Comment
Please, Sign In to add comment