Advertisement
DrupalCustom

formModifications

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