Advertisement
DrupalCustom

ModuleFile

May 15th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.41 KB | None | 0 0
  1. <?php
  2. drupal_add_css(drupal_get_path('module', 'freeway') . '/css/dashboard_file.css');
  3.  
  4. function freeway_menu() {
  5.   $type_url_str = "";
  6.  
  7.   $items['admin/config/freeway'] = array(
  8.     'title' => 'Freeway',
  9.     'description' => 'Freeway functionalities.',
  10.     'page callback' => 'drupal_get_form',
  11.     'page arguments' => array('freeway_admin_settings'),
  12.     'access arguments' => array('translate content'),
  13.     'type' => MENU_NORMAL_ITEM,
  14.     'file' => 'freeway.admin.inc',
  15.   );
  16.  
  17.   $items['user/%user/createFreewayProject'] = array(
  18.     'title' => 'Create Freeway Project',
  19.     'page callback' => 'drupal_get_form',
  20.     'page arguments' => array('create_freeway_project'),
  21.     'access callback' => 'node_access',
  22.     'access arguments' => array('update', 1),
  23.     'weight' => 1,
  24.     'file' => 'freeway.admin.inc',
  25.     'type' => MENU_LOCAL_TASK,
  26.   );
  27.  
  28.   $items['user/%user/freewayDashboard'] = array(
  29.     'title' => 'Freeway Dashboard',
  30.     'page callback' => 'drupal_get_form',
  31.     'page arguments' => array('freeway_dashboard'),
  32.     'access callback' => 'node_access',
  33.     'access arguments' => array('update', 1),
  34.     'weight' => 1,
  35.     'file' => 'freeway.admin.inc',
  36.     'type' => MENU_LOCAL_TASK,
  37.   );
  38.  
  39.   $items['user/%user/freewayDashboardDetails'] = array(
  40.     'page callback' => 'drupal_get_form',
  41.     'page arguments' => array('freeway_dashboard_details'),
  42.     'access callback' => 'node_access',
  43.     'access arguments' => array('update', 1),
  44.     'weight' => 1,
  45.     'file' => 'freeway.admin.inc',
  46.   );
  47.  
  48.  
  49.   $items['user/%user/freewayRetrieve'] = array(
  50.     'page callback' => 'drupal_get_form',
  51.     'page arguments' => array('freeway_retrieve'),
  52.     'access callback' => 'node_access',
  53.     'access arguments' => array('update', 1),
  54.     'weight' => 1,
  55.     'file' => 'freeway.admin.inc',
  56.   );
  57.  
  58.  
  59.   $items['user/%user/freewayUserMapping'] = array(
  60.     'title' => 'Freeway User Mapping',
  61.     'page callback' => 'drupal_get_form',
  62.     'page arguments' => array('freeway_user_mapping'),
  63.     'access callback' => 'node_access',
  64.     'access arguments' => array('update', 1),
  65.     'weight' => 1,
  66.     'file' => 'freeway.admin.inc',
  67.     'type' => MENU_LOCAL_TASK,
  68.   );
  69.  
  70.   $items['user/%user/freewayGlobalUser'] = array(
  71.     'title' => 'Freeway Global User Mapping',
  72.     'page callback' => 'drupal_get_form',
  73.     'page arguments' => array('freeway_user_mapping_global'),
  74.     'access callback' => 'node_access',
  75.     'access arguments' => array('update', 1),
  76.     'weight' => 1,
  77.     'file' => 'freeway.admin.inc',
  78.     'type' => MENU_CALLBACK,
  79.   );
  80.  
  81.   $items['user/%user/freewayNonGlobalUser'] = array(
  82.     'title' => 'Freeway Non Global User Mapping',
  83.     'page callback' => 'drupal_get_form',
  84.     'page arguments' => array('freeway_user_mapping_non_global'),
  85.     'access callback' => 'node_access',
  86.     'access arguments' => array('update', 1),
  87.     'weight' => 1,
  88.     'file' => 'freeway.admin.inc',
  89.     'type' => MENU_CALLBACK,
  90.   );
  91.  
  92.   return $items;
  93. }
  94.  
  95. function freeway_permission() {
  96.   return array(
  97.     'translate content' => array(
  98.       'title' => t('translate content'),
  99.       'description' => t('TODO Add a description for \'translate content\''),
  100.     ),
  101.   );
  102. }
  103.  
  104. function freeway_theme() {
  105.   drupal_add_js(drupal_get_path('module', 'freeway') . '/js/dashboardscript.js');
  106.   return array('freeway_dashboard' => array('render element' => 'form'), 'freeway_dashboard_details' => array('render element' => 'form'), 'freeway_user_mapping_non_global' => array('render element' => 'form'));
  107. }
  108.  
  109.  
  110.  
  111. function theme_freeway_dashboard($variables) {
  112.   $form = $variables['form'];
  113.   $url = "";
  114.   drupal_add_js(drupal_get_path('module', 'freeway') . '/js/dashboardscript.js');
  115.   global $user;
  116.   $rows = array();
  117.   foreach (element_children($form) as $key) {
  118.     $row = array();
  119.     if (isset($form[$key]['projectID'])) {
  120.       $status = drupal_render($form['featured'][$key]);
  121.       $row[] = array('data' => l(drupal_render($form[$key]['projectID']), 'user/' . $user->uid . '/freewayDashboardDetails', array('query' => array('project_id' => $form[$key]['projectID']['#markup']))));
  122.  
  123.       $row[] = array('data' => drupal_render($form[$key]['projectDesc']));
  124.       $row[] = array('data' => drupal_render($form[$key]['projectStatusCode']));
  125.  
  126.       $rows[] = $row;
  127.  
  128.       l(t('Title'), $url, array('attributes' => array('target' => '_blank')));
  129.     }
  130.  
  131.   }
  132.  
  133.   $header = array();
  134.   $header[] = t('Project ID');
  135.   $header[] = t('Project Description');
  136.   $header[] = t('Project Status');
  137.  
  138.   $output = drupal_render_children($form) .'<div class="table_overflow">' . theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('size' => 10, 'class' => array('table_class')))) . '</div>';
  139.  
  140.  
  141.   return $output;
  142.  
  143.  
  144. }
  145.  
  146. function theme_freeway_dashboard_details($variables) {
  147.   $form = $variables['form'];
  148.   drupal_add_js(drupal_get_path('module', 'freeway') . '/js/dashboardscript.js');
  149.   global $user;
  150.   $pidobtained = $_GET['project_id'];
  151.  
  152.   $rows = array();
  153.  
  154.   foreach (element_children($form) as $key) {
  155.  
  156.     $row = array();
  157.     $row[] = array('data' => drupal_render($form[$key]['FileID']));
  158.     $row[] = array('data' => drupal_render($form[$key]['Filename']));
  159.     $row[] = array('data' => drupal_render($form[$key]['SourceLanguageID']));
  160.     $row[] = array('data' => drupal_render($form[$key]['TargetLanguageID']));
  161.  
  162.     if ($form[$key]['StatusID']['#markup'] == 'READY') {
  163.  
  164.  
  165.       $row[] = array(
  166.         'data' => l(drupal_render($form[$key]['StatusID']), 'user/' . $user->uid . '/freewayRetrieve', array('query' => array('fileId' => $form[$key]['FileID']['#markup'], 'projectID' => $pidobtained, 'fileName' => $form[$key]['Filename']['#markup']), 'attributes' => array('class' => 'common_link_class'))),
  167.       );
  168.  
  169.     }
  170.     else {
  171.       $row[] = array('data' => drupal_render($form[$key]['StatusID']));
  172.     }
  173.  
  174.    // $row[] = array('data' => drupal_render($form[$key]['StatusDescription']));
  175.     $rows[] = $row;
  176.  
  177.  
  178.   }
  179.   $header = array();
  180.   $header[] = t('File ID');
  181.   $header[] = t('File Name');
  182.   $header[] = t('Source Language');
  183.   $header[] = t('Target Language');
  184.   $header[] = t('Status ID');
  185.  // $header[] = t('Status Description');
  186.  
  187.   $output = '<div class="table_overflow">' . theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('size' => 10, 'class' => array('table_class')))) . '</div>';
  188.  
  189.   $output .= drupal_render_children($form);
  190.   return $output;
  191.  
  192. }
  193.  
  194.  
  195. function theme_freeway_user_mapping_non_global($variables) {
  196.   $form = $variables['form'];
  197.   drupal_add_js(drupal_get_path('module', 'freeway') . '/js/dashboardscript.js');
  198.   global $user;
  199.   $rows = array();
  200.   foreach ($form['users']['#value'] as $key => $value) {
  201.     $rows[] = array($value, drupal_render($form['textfield1_' . $value]), drupal_render($form['textfield2_' . $value]));
  202.   }
  203.   $header = array();
  204.   $header[] = t('Drupal UserName');
  205.   $header[] = t('Freeway UserName');
  206.   $header[] = t('Freeway Password');
  207.  
  208.   $output = '<div class="table_overflow">' . theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('size' => 10, 'class' => array('table_class')))) . '</div>';
  209.  
  210.   $output .= drupal_render_children($form);
  211.  
  212.   return $output;
  213.  
  214. }
  215.  
  216.  
  217.  
  218. function freeway_node_load($node, $types) {
  219. global $language;
  220.  
  221.   $resultLangMode = db_query("SELECT lang_mode_id FROM {freeway_language_mode}");
  222.   $langMode = $resultLangMode -> rowCount();  
  223.  
  224.  
  225.  $nodeSrc = '';
  226.  $frewayLang = '';
  227.  
  228. foreach($node as $n){
  229. $tempId = $n->nid;
  230. $tempSrcLang = $n->language;
  231. }
  232.    
  233.  
  234.  
  235.   $tempTarLang = $language->language;
  236.  
  237.    
  238.     $resultLangsSrc = db_query("SELECT freeway_lang_id FROM {freeway_language_map} where drupal_lang_id  = '$tempSrcLang'");
  239.  
  240.   $rowsLanguage = $resultLangsSrc->rowCount();  
  241.  
  242.      if ($rowsLanguage == 0) {
  243.         drupal_get_messages();
  244.         drupal_set_message("Log in with Freeway Credentials to avail Freeway language offerings!");
  245.         drupal_goto('user');
  246.       }
  247.         else {    
  248.         foreach($resultLangsSrc as $recordLang )
  249.         {
  250.           $nodeSrc = $recordLang->freeway_lang_id;        
  251.         }
  252.       }
  253.      
  254.          
  255.      
  256.       $resultLangsTar = db_query("SELECT freeway_lang_id FROM {freeway_language_map} where drupal_lang_id  = '$tempTarLang '");
  257.      
  258.        $rowsLanguageTar = $resultLangsTar->rowCount();
  259.          if ($rowsLanguageTar == 0) {
  260.             drupal_get_messages();
  261.             drupal_set_message("This Drupal language is unavailable for your Freeway account!");
  262.             drupal_goto('user');
  263.           }
  264.         else {    
  265.         foreach($resultLangsTar as $recordLangTar )
  266.         {
  267.           $frewayLang = $recordLangTar->freeway_lang_id;        
  268.         }
  269.       }
  270.  
  271.      
  272.      
  273.      
  274.  
  275.   if ($tempSrcLang == $tempTarLang) {
  276.     $frewayLang = 'same';
  277.   }
  278.  
  279.  
  280.    
  281.   $result = db_query("SELECT node_title,node_body FROM {freeway}
  282.                      WHERE node_id = '$tempId'
  283.                      AND src_lang ='$nodeSrc'
  284.                      AND tar_lang='$frewayLang'");
  285.  
  286. $rowsUsPw = $result->rowCount();
  287.      
  288.   if($rowsUsPw != 0)
  289.    {
  290.       foreach ($result as $record) {
  291.       foreach($node as $inner){
  292.                    
  293.             $inner->body['und'][0]['safe_value']= $record->node_body.' Translated from Freeway';   
  294.             $inner->title = $record->node_title.' Translated from Freeway';
  295.        
  296.         }
  297.        
  298.       }
  299.   }
  300.  
  301.  
  302.  
  303.  
  304.   else if ($frewayLang!= 'same'){
  305.    drupal_get_messages();
  306.    drupal_set_message("The version of the content belonging to the chosen language is unavailable.");
  307.   }
  308.  
  309.  
  310.  
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement