DrupalCustom

formMod

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