Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @file
- * Testing some ideas about heirarchical forms.
- */
- /**
- * Instance of hook_menu().
- */
- function test_menu() {
- $items = array();
- // Our little test form.
- $items['test/select'] = array(
- 'title' => t('Source / Target'),
- 'description' => t('Choose a source and a target'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('test_source_target'),
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- // Select a source and a target.
- function test_source_target($form, &$form_state) {
- $form = array();
- global $finalFunctionUserName;
- global $finalFunctionPassword;
- global $ticket;
- $arrayForSendTranslation = array();
- $arrayForSendTranslation = formModCredentialProvider_test();
- $finalFunctionUserName = $arrayForSendTranslation[0];
- $finalFunctionPassword = $arrayForSendTranslation[1];
- $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace" => 1));
- $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace" => 1));
- try {
- $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
- $ticket = ($arrResponse->LogonResult);
- $getSrcLang = $ServicesLink->GetSourceLanguages(array('Ticket' => $ticket));
- //$array has the list of source languages.
- $array = array();
- $arrayTarget = array();
- $forTarLang = array();
- foreach ($getSrcLang->GetSourceLanguagesResult->Languages->Language as $language) {
- $array[$language->ID] = $language->Description . "_" . $language->ID;
- $forTarLang[] = $language->ID;
- }
- }
- catch (SoapFault $exception) {
- drupal_get_messages();
- drupal_set_message("The following exception took place.1" . $exception . "Kindly check Freeway mapping");
- drupal_goto("user");
- }
- // Because this is a test we have some hard coded values.
- // The sources.
- $source = array(
- 'cat' => t('Cat'),
- 'dog' => t('Dog'),
- 'reptile' => t('Reptile'),
- );
- // If we have a value for the first dropdown from $form_state['values'] we use
- // this both as the default value for the first dropdown and also as a
- // parameter to pass to the function that retrieves the options for the
- // second dropdown.
- $selected = isset($form_state['values']['source']) ? $form_state['values']['source'] : key($array);
- $form['source'] = array(
- '#type' => 'select',
- '#title' => t('Source'),
- '#options' => $array,
- '#default_value' => $selected,
- '#ajax' => array(
- 'callback' => 'test_source_target_callback',
- 'wrapper' => 'dropdown-second-replace',
- ),
- );
- $form['target'] = array(
- '#type' => 'select',
- '#title' => $options_first[$selected] . ' ' . t('Instruments'),
- '#prefix' => '<div id="dropdown-second-replace">',
- '#suffix' => '</div>',
- '#multiple' => true,
- '#options' => _get_target($selected),
- '#default_value' => isset($form_state['values']['target']) ? $form_state['values']['target'] : '',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- );
- return $form;
- }
- /**
- * Selects just the second dropdown to be returned for re-rendering
- */
- function test_source_target_callback($form, $form_state) {
- return $form['target'];
- }
- // Fetch the target.
- function _get_target($selected) {
- watchdog('test', $selected);
- global $finalFunctionUserName;
- global $finalFunctionPassword;
- $arrayT = array();
- $LoginClient = new SoapClient("https://freeway.demo.lionbridge.com/vojo/FreewayAuth.asmx?wsdl", array("trace" => 1));
- $ServicesLink = new SoapClient("https://freeway.demo.lionbridge.com/vojo/Service.asmx?wsdl", array("trace" => 1));
- try {
- $arrResponse = $LoginClient->Logon(array('Username' => $finalFunctionUserName, 'Password' => $finalFunctionPassword));
- $ticket = ($arrResponse->LogonResult);
- $getTarLang = $ServicesLink->GetTargetLanguages(array('Ticket' => $ticket, 'SourceLanguageID' => $selected));
- foreach ($getTarLang->GetTargetLanguagesResult->Languages->Language as $languageT) {
- $arrayT[$languageT->ID] = $languageT->Description . "_" . $languageT->ID;
- }
- drupal_get_messages();
- drupal_set_message("Here check the arr length ".count($arrayT));
- drupal_goto("user");
- }
- catch (SoapFault $exception) {
- drupal_get_messages();
- drupal_set_message("The following exception took place." . $exception . "Kindly check Freeway mapping");
- drupal_goto("user");
- }
- // The targets.
- /*
- $target = array(
- 'cat' => array(
- 'house_cat' => 'House cat',
- 'lion' => 'Lion',
- 'Leopard' => 'Leopard',
- 'cheetah' => 'Cheetah',
- ),
- 'dog' => array(
- 'alsatian' => 'Alsatian',
- 'collie' => 'Collie',
- ),
- 'reptile' => array(
- 'lizard' => 'Lizard',
- 't_rex' => 'T-Rex',
- 'tortoise' => 'Tortoise',
- ),
- );
- */
- $target = $arrayT;
- return $target[$selected];
- }
- function formModCredentialProvider_test() {
- $arrayWithCredentials = array();
- global $user;
- /*
- 1.Get the current mode.
- 1.1. If curr mode = 0 ;
- Navigate to a page saying "Kindly use user mapping options to provide Freeway Credentials"
- 1.2 If curr mode = 1 ;
- Select freeway uname and pwrd from global table and set them to the variables.
- if uname = '' or pwrd = '' ; -> navigate to page saying "The Freway credentials have not been entered
- correctly in tha mapping page"
- else set the variable with the value obtained.
- 1.3 else if curr mode = 2;
- Get currently logged in user name.
- Select freeway uname and pwrd from non global table where drupal username = 'currently logged in user name'
- if uname = '' or pwrd = '' ; -> navigate to page saying "The Freway credentials have not been entered
- correctly in tha mapping page"
- else set the variable with the value obtained.
- */
- $resultUsPw = db_query("SELECT mode_id FROM {freeway_mode} where sr_id = 1");
- // $rowsUsPw = mysql_num_rows($resultUsPw);
- $rowsUsPw = $resultUsPw->rowCount();
- if ($rowsUsPw == 0) {
- drupal_get_messages();
- drupal_set_message("The Freeway user mapping for Drupal users has not been completed. Kindly associate
- Drupal users with Freeway credentials");
- drupal_goto('user/' . $user->uid . '/freewayUserMapping');
- }
- else {
- //while ($recordUsPw = db_fetch_object($resultUsPw))
- foreach($resultUsPw as $recordUsPw )
- {
- $modeValueUsPw = $recordUsPw->mode_id;
- }
- if ($modeValueUsPw == '0') {
- drupal_get_messages();
- drupal_set_message("Kindly use user mapping options to provide Freeway Credentials");
- drupal_goto('user/' . $user->uid . '/freewayUserMapping');
- }
- else if ($modeValueUsPw == '1') {
- $globalResult = db_query("SELECT freeway_global_username,freeway_global_password FROM {freeway_global_user} where sr_id = 1");
- //$rowsGlobalUsPw = mysql_num_rows($globalResult);
- $rowsGlobalUsPw = $globalResult->rowCount();
- if ($rowsGlobalUsPw == 0) {
- drupal_get_messages();
- drupal_set_message("There is no Freeway credential mapped for the Global user role logged ");
- drupal_goto('user/' . $user->uid . '/freewayGlobalUser');
- }
- else {
- // while ($recordUsPwGl = db_fetch_object($globalResult))
- foreach($globalResult as $recordUsPwGl)
- {
- $freewayGlobalUserName = $recordUsPwGl->freeway_global_username;
- $freewayGlobalPassword = $recordUsPwGl->freeway_global_password;
- if ((strlen($freewayGlobalUserName) == '0') || (strlen($freewayGlobalPassword) == '0')) {
- drupal_get_messages();
- drupal_set_message("Kindly use user mapping options to provide Freeway Credentials for the Global user");
- drupal_goto('user/' . $user->uid . '/freewayGlobalUser');
- }
- else {
- $finalUserName = $freewayGlobalUserName;
- $finalPassword = $freewayGlobalPassword;
- }
- }
- }
- }
- else if ($modeValueUsPw == '2') {
- $userNameCurr = $user->name;
- // TODO Please convert this statement to the D7 database API syntax.
- $nonGlobalResult = db_query("SELECT freeway_username ,freeway_password FROM {freeway_users} where drupal_username = '$userNameCurr'");
- // $rowsNonGlobalUsPw = mysql_num_rows($nonGlobalResult);
- $rowsNonGlobalUsPw = $nonGlobalResult->rowCount();
- if ($rowsNonGlobalUsPw == 0) {
- drupal_get_messages();
- drupal_set_message("There are no Freeway credentials mapped for the currently logged in user " . $userNameCurr . ".");
- drupal_goto('user/' . $user->uid . '/freewayNonGlobalUser');
- }
- else {
- //while ($recordUsPwNonGl = db_fetch_object($nonGlobalResult))
- foreach ($nonGlobalResult as $recordUsPwNonGl )
- {
- $freewayNonGlobalUserName = $recordUsPwNonGl->freeway_username;
- $freewayNonGlobalPassword = $recordUsPwNonGl->freeway_password;
- if ((strlen($freewayNonGlobalUserName) == '0') || (strlen($freewayNonGlobalPassword) == '0')) {
- drupal_get_messages();
- drupal_set_message("There are no Freeway credentials mapped for the currently logged in user " . $userNameCurr . ".");
- drupal_goto('user/' . $user->uid . '/freewayNonGlobalUser');
- }
- else {
- $finalUserName = $freewayNonGlobalUserName;
- $finalPassword = $freewayNonGlobalPassword;
- }
- }
- }
- }
- }
- $arrayWithCredentials[0] = $finalUserName;
- $arrayWithCredentials[1] = $finalPassword;
- return $arrayWithCredentials;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement