Advertisement
DrupalCustom

codeThusFar

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