Changeset 5328

Show
Ignore:
Timestamp:
12/02/07 00:53:34 (6 years ago)
Author:
p_lindheimer
Message:

add language module that allows language change in the call flow and adds language attribute to extensions/users

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.4/languages/functions.inc.php

    r5276 r5328  
    11<?php 
    22 
    3 function miscapps_contexts() { 
    4   // return an associative array with context and description 
    5   foreach (miscapps_list() as $row) { 
    6     $contexts[] = array( 
    7       'context' => 'app-miscapps-'.$row['miscapps_id'],  
    8       'description'=> 'Misc Application: '.$row['description'], 
    9       'source' => 'Misc Applications', 
    10     ); 
    11   } 
    12   return $contexts; 
    13 
    14  
    15 function miscapps_get_config($engine) { 
     3function languages_destinations() { 
     4  // return an associative array with destination and description 
     5  foreach (languages_list() as $row) { 
     6    $extens[] = array('destination' => 'app-languages,' . $row['language_id'] . ',1', 'description' => $row['description']); 
     7  } 
     8  return $extens; 
     9
     10 
     11function languages_getdest($exten) { 
     12  return array('app-languages,'.$exten.',1'); 
     13
     14 
     15function languages_getdestinfo($dest) { 
     16  global $active_modules; 
     17 
     18  if (substr(trim($dest),0,14) == 'app-languages,') { 
     19    $exten = explode(',',$dest); 
     20    $exten = $exten[1]; 
     21    $thisexten = languages_get($exten); 
     22    if (empty($thisexten)) { 
     23      return array(); 
     24    } else { 
     25      $type = isset($active_modules['languages']['type'])?$active_modules['languages']['type']:'setup'; 
     26      return array('description' => 'Language : '.$thisexten['description'], 
     27                   'edit_url' => 'config.php?display=languages&type='.$type.'&extdisplay='.urlencode($exten), 
     28                  ); 
     29    } 
     30  } else { 
     31    return false; 
     32  } 
     33
     34 
     35function languages_get_config($engine) { 
    1636  global $ext; 
    1737  switch ($engine) { 
    1838    case 'asterisk': 
    19       foreach (miscapps_list(true) as $row) { 
    20         if ($row['enabled']) { 
    21           $ext->add('app-miscapps-'.$row['miscapps_id'], $row['ext'], '', new ext_noop('Running miscapp '.$row['miscapps_id'].': '.$row['description'])); 
    22           $ext->add('app-miscapps-'.$row['miscapps_id'], $row['ext'], '', new ext_goto($row['dest'])); 
    23            
    24           $ext->addInclude('from-internal-additional', 'app-miscapps-'.$row['miscapps_id']); 
    25         } 
     39      $ext->addInclude('from-internal-additional', 'app-languages'); 
     40      foreach (languages_list() as $row) { 
     41          $ext->add('app-languages',$row['language_id'], '', new ext_noop('Changing Channel to language: '.$row['lang_code'].' ('.$row['description'].')')); 
     42          $ext->add('app-languages',$row['language_id'], '', new ext_setvar('LANGUAGE()',$row['lang_code'])); 
     43          $ext->add('app-languages',$row['language_id'], '', new ext_goto($row['dest'])); 
    2644      } 
    2745    break; 
     
    2947} 
    3048 
    31  
    32 /**  Get a list of all miscapps 
    33  * Optional parameter is get_ext. Potentially slow, because each row is extracted from the featurecodes table 
    34  * one-by-one 
     49/**  Get a list of all languages 
    3550 */ 
    36 function miscapps_list($get_ext = false) { 
    37   global $db; 
    38   $sql = "SELECT miscapps_id, description, dest FROM miscapps ORDER BY description "; 
     51function languages_list() { 
     52  global $db; 
     53  $sql = "SELECT language_id, description, lang_code, dest FROM languages ORDER BY description "; 
    3954  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    4055  if(DB::IsError($results)) { 
    41     die_freepbx($results->getMessage()."<br><br>Error selecting from miscapps");   
    42   } 
    43    
    44   if ($get_ext) { 
    45     foreach (array_keys($results) as $idx) { 
    46       $fc = new featurecode('miscapps', 'miscapp_'.$results[$idx]['miscapps_id']); 
    47       $results[$idx]['ext'] = $fc->getDefault(); 
    48       $results[$idx]['enabled'] = $fc->isEnabled(); 
    49     } 
    50   } 
    51    
     56    die_freepbx($results->getMessage()."<br><br>Error selecting from languages");  
     57  } 
    5258  return $results; 
    5359} 
    5460 
    55 function miscapps_get($miscapps_id) { 
    56   global $db; 
    57   $sql = "SELECT miscapps_id, description, ext, dest FROM miscapps WHERE miscapps_id = ".addslashes($miscapps_id); 
     61function languages_get($language_id) { 
     62  global $db; 
     63  $sql = "SELECT language_id, description, lang_code, dest FROM languages WHERE language_id = ".addslashes($language_id); 
    5864  $row = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    5965  if(DB::IsError($row)) { 
    60     die_freepbx($row->getMessage()."<br><br>Error selecting row from miscapps");   
     66    die_freepbx($row->getMessage()."<br><br>Error selecting row from languages");  
    6167  } 
    6268   
    63   // we want to get the ext from featurecodes 
    64   $fc = new featurecode('miscapps', 'miscapp_'.$row['miscapps_id']); 
    65   $row['ext'] = $fc->getDefault(); 
    66   $row['enabled'] = $fc->isEnabled(); 
    67  
    6869  return $row; 
    6970} 
    7071 
    71 function miscapps_add($description, $ext, $dest) { 
    72   global $db; 
    73   $sql = "INSERT INTO miscapps (description, ext, dest) VALUES (". 
     72function languages_add($description, $lang_code, $dest) { 
     73  global $db; 
     74  $sql = "INSERT INTO languages (description, lang_code, dest) VALUES (". 
    7475    "'".addslashes($description)."', ". 
    75     "'".addslashes($ext)."', ". 
     76    "'".addslashes($lang_code)."', ". 
    7677    "'".addslashes($dest)."')"; 
    7778  $result = $db->query($sql); 
     
    7980    die_freepbx($result->getMessage().$sql); 
    8081  } 
    81   //get id.. 
    82   $miscapps_id = $db->getOne('SELECT LAST_INSERT_ID()'); 
    83   if (DB::IsError($miscapps_id)) { 
    84     //TODO -- handle this 
    85   } 
    86    
    87   $fc = new featurecode('miscapps', 'miscapp_'.$miscapps_id); 
    88   $fc->setDescription($description); 
    89   $fc->setDefault($ext, true); 
    90   $fc->update(); 
    91 
    92  
    93 function miscapps_delete($miscapps_id) { 
    94   global $db; 
    95   $sql = "DELETE FROM miscapps WHERE miscapps_id = ".addslashes($miscapps_id); 
     82
     83 
     84function languages_delete($language_id) { 
     85  global $db; 
     86  $sql = "DELETE FROM languages WHERE language_id = ".addslashes($language_id); 
    9687  $result = $db->query($sql); 
    9788  if(DB::IsError($result)) { 
    9889    die_freepbx($result->getMessage().$sql); 
    9990  } 
    100    
    101   $fc = new featurecode('miscapps', 'miscapp_'.$miscapps_id); 
    102   $fc->delete(); 
    103 
    104  
    105 function miscapps_edit($miscapps_id, $description, $ext, $dest, $enabled=true) {  
    106   global $db; 
    107   $sql = "UPDATE miscapps SET ". 
     91
     92 
     93function languages_edit($language_id, $description, $lang_code, $dest) {  
     94  global $db; 
     95  $sql = "UPDATE languages SET ". 
    10896    "description = '".addslashes($description)."', ". 
    109     "ext = '".addslashes($ext)."', ". 
     97    "lang_code = '".addslashes($lang_code)."', ". 
    11098    "dest = '".addslashes($dest)."' ". 
    111     "WHERE miscapps_id = ".addslashes($miscapps_id); 
     99    "WHERE language_id = ".addslashes($language_id); 
    112100  $result = $db->query($sql); 
    113101  if(DB::IsError($result)) { 
    114102    die_freepbx($result->getMessage().$sql); 
    115103  } 
     104} 
     105 
     106function languages_configpageinit($pagename) { 
     107  global $currentcomponent; 
     108 
     109  $action = isset($_REQUEST['action'])?$_REQUEST['action']:null; 
     110  $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 
     111  $extension = isset($_REQUEST['extension'])?$_REQUEST['extension']:null; 
     112  $tech_hardware = isset($_REQUEST['tech_hardware'])?$_REQUEST['tech_hardware']:null; 
     113 
     114  // We only want to hook 'users' or 'extensions' pages. 
     115  if ($pagename != 'users' && $pagename != 'extensions')  
     116    return true; 
     117  // On a 'new' user, 'tech_hardware' is set, and there's no extension. Hook into the page. 
     118  if ($tech_hardware != null || $pagename == 'users') { 
     119    language_applyhooks(); 
     120    $currentcomponent->addprocessfunc('languages_configprocess', 5); 
     121  } elseif ($action=="add") { 
     122    // We don't need to display anything on an 'add', but we do need to handle returned data. 
     123    $currentcomponent->addprocessfunc('languages_configprocess', 5); 
     124  } elseif ($extdisplay != '') { 
     125    // We're now viewing an extension, so we need to display _and_ process. 
     126    language_applyhooks(); 
     127    $currentcomponent->addprocessfunc('languages_configprocess', 5); 
     128  } 
     129} 
     130 
     131function language_applyhooks() { 
     132  global $currentcomponent; 
     133 
     134  // Add the 'process' function - this gets called when the page is loaded, to hook into  
     135  // displaying stuff on the page. 
     136  $currentcomponent->addguifunc('languages_configpageload'); 
     137} 
     138 
     139// This is called before the page is actually displayed, so we can use addguielem(). 
     140function languages_configpageload() { 
     141  global $currentcomponent; 
     142 
     143  // Init vars from $_REQUEST[] 
     144  $action = isset($_REQUEST['action'])?$_REQUEST['action']:null; 
     145  $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 
    116146   
    117   $fc = new featurecode('miscapps', 'miscapp_'.$miscapps_id); 
    118   $fc->setDescription($description); 
    119   $fc->setDefault($ext, true); 
    120   $fc->setEnabled($enabled); 
    121   $fc->update(); 
    122 
    123  
    124 function miscapps_check_destinations($dest=true) { 
     147  // Don't display this stuff it it's on a 'This xtn has been deleted' page. 
     148  if ($action != 'del') { 
     149    $langcode = languages_user_get($extdisplay); 
     150 
     151    $section = _('Language'); 
     152    $msgInvalidLanguage = _('Please enter a valid Language Code'); 
     153    $currentcomponent->addguielem($section, new gui_textbox('langcode', $langcode, _('Language Code'), _('The language code for this user. This will result in messages such as voiclangcode prompts to use the selected language if installed.'), "!isAlphanumeric()", $msgInvalidLanguage, true)); 
     154  } 
     155
     156 
     157function languages_configprocess() { 
     158  //create vars from the request 
     159  $action = isset($_REQUEST['action'])?$_REQUEST['action']:null; 
     160  $ext = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 
     161  $extn = isset($_REQUEST['extension'])?$_REQUEST['extension']:null; 
     162  $langcode = isset($_REQUEST['langcode'])?$_REQUEST['langcode']:null; 
     163 
     164  if ($ext==='') {  
     165    $extdisplay = $extn;  
     166  } else { 
     167    $extdisplay = $ext; 
     168  }  
     169  if ($action == "add" || $action == "edit") { 
     170    languages_user_update($extdisplay, $langcode); 
     171  } elseif ($action == "del") { 
     172    languages_user_del($extdisplay); 
     173  } 
     174
     175 
     176function languages_user_get($xtn) { 
     177  global $astman; 
     178 
     179  // Retrieve the language configuraiton from this user from ASTDB 
     180  $langcode = $astman->database_get("AMPUSER",$xtn."/language"); 
     181 
     182  return $langcode; 
     183
     184 
     185function languages_user_update($ext, $langcode) { 
     186  global $astman; 
     187   
     188  if ($ena === 'disabled') { 
     189    languages_user_del($ext); 
     190  } else { 
     191    // Update the settings in ASTDB 
     192    $astman->database_put("AMPUSER",$ext."/language",$langcode); 
     193  } 
     194
     195 
     196function languages_user_del($ext) { 
     197  global $astman; 
     198 
     199  // Clean up the tree when the user is deleted 
     200  $astman->database_deltree("AMPUSER/$ext/language"); 
     201
     202 
     203function languages_check_destinations($dest=true) { 
    125204  global $active_modules; 
    126205 
     
    129208    return $destlist; 
    130209  } 
    131   $sql = "SELECT miscapps_id, dest, description FROM miscapps "; 
     210  $sql = "SELECT language_id, dest, description FROM languages "; 
    132211  if ($dest !== true) { 
    133212    $sql .= "WHERE dest in ('".implode("','",$dest)."')"; 
     
    135214  $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC); 
    136215 
    137   $type = isset($active_modules['miscapps']['type'])?$active_modules['miscapps']['type']:'setup'; 
     216  $type = isset($active_modules['languages']['type'])?$active_modules['languages']['type']:'setup'; 
    138217 
    139218  foreach ($results as $result) { 
    140219    $thisdest = $result['dest']; 
    141     $thisid   = $result['miscapps_id']; 
     220    $thisid   = $result['language_id']; 
    142221    $destlist[] = array( 
    143222      'dest' => $thisdest, 
    144       'description' => 'Misc Application: '.$result['description'], 
    145       'edit_url' => 'config.php?display=miscapps&type='.$type.'&extdisplay='.urlencode($thisid), 
     223      'description' => 'Language Change: '.$result['description'], 
     224      'edit_url' => 'config.php?display=languages&type='.$type.'&extdisplay='.urlencode($thisid), 
    146225    ); 
    147226  } 
    148227  return $destlist; 
    149228} 
    150  
    151229?> 
  • modules/branches/2.4/languages/install.php

    r4767 r5328  
    22 
    33global $db; 
    4 global $amp_conf; 
    54 
    65$autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT"; 
    7 $sql = "CREATE TABLE IF NOT EXISTS miscapps ( 
    8   miscapps_id INTEGER NOT NULL PRIMARY KEY $autoincrement, 
    9   ext VARCHAR( 50 ) , 
     6$sql = "CREATE TABLE IF NOT EXISTS languages ( 
     7  language_id INTEGER NOT NULL PRIMARY KEY $autoincrement, 
     8  lang_code VARCHAR( 50 ) , 
    109  description VARCHAR( 50 ) , 
    1110  dest VARCHAR( 255 ) 
     
    1413$check = $db->query($sql); 
    1514if(DB::IsError($check)) { 
    16   die_freepbx("Can not create miscdests table\n"); 
    17 
    18 $results = array(); 
    19 $sql = "SELECT miscapps_id, dest FROM miscapps"; 
    20 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    21 if (!DB::IsError($results)) { // error - table must not be there 
    22   foreach ($results as $result) { 
    23     $old_dest    = $result['dest']; 
    24     $miscapps_id = $result['miscapps_id']; 
    25  
    26     $new_dest = merge_ext_followme(trim($old_dest)); 
    27     if ($new_dest != $old_dest) { 
    28       $sql = "UPDATE miscapps SET dest = '$new_dest' WHERE miscapps_id = $miscapps_id  AND dest = '$old_dest'"; 
    29       $results = $db->query($sql); 
    30       if(DB::IsError($results)) { 
    31         die_freepbx($results->getMessage()); 
    32       } 
    33     } 
    34   } 
     15  die_freepbx("Can not create languages table\n"); 
    3516} 
    3617 
  • modules/branches/2.4/languages/module.xml

    r4924 r5328  
    11<module> 
    2   <rawname>miscapps</rawname> 
    3   <name>Misc Applications</name> 
    4   <version>0.2.3.5</version> 
     2  <rawname>languages</rawname> 
     3  <name>Languages</name> 
     4  <version>0.8.0</version> 
    55  <type>setup</type> 
    66  <category>Internal Options &amp; Configuration</category> 
    77  <description> 
    8     Adds the ability to create feature codes that can go to any FreePBX destination (such as an IVR or queue) 
     8    Adds the ability to changes the language within a call flow and add language attribute to users. 
    99  </description> 
    1010  <menuitems> 
    11     <miscapps>Misc Applications</miscapps> 
     11    <languages>Languages</languages> 
    1212  </menuitems> 
    1313  <changelog> 
    14     *0.2.3.5* #2305 Feature Status broken 
    15     *0.2.3.3* fixed some undefined variables, bump for rc1 
    16     *0.2.3.2* #2177: removed apparently corrupted newline at end of file 
    17     *0.2.3.1* added proper uninstall, removes any feature codes and then table 
    18     *0.2.3* #1902 miscapp always sets/pulls default code now regardless of custom override in featurecodes 
    19     *0.2.2* added SQLite3 support, fixes http://freepbx.org/trac/ticket/1775 
    20     *0.2.1.1* changed freePBX to FreePBX 
    21     *0.2.1* merge findmefollow/core extension destinations if any 
    22     *0.2* Fix bug with adding new apps 
    23     *0.1.1* Fixed publish location for trunk/2.3 repository 
     14    *0.8.0* First release of module 
    2415  </changelog> 
    25   <location>release/2.3/miscapps-0.2.3.5.tgz</location> 
     16  <location>release/2.4/languages-0.8.0tgz</location> 
    2617  <md5sum>b05759ac4981e263fd4b8606283c7a8a</md5sum> 
    2718</module> 
  • modules/branches/2.4/languages/uninstall.php

    r4583 r5328  
    22 
    33global $db; 
    4 global $amp_conf; 
    54 
    6 $miscapps_arr = miscapps_list(); 
    7 foreach ($miscapps_arr as $item) { 
    8   echo "removing ".$item['description'].".."; 
    9   miscapps_delete($item['miscapps_id']); 
    10   echo "done<br>\n"; 
    11 
    12  
    13 echo "dropping table miscapps.."; 
    14 sql("DROP TABLE IF EXISTS `miscapps`"); 
     5echo "dropping table languages.."; 
     6sql("DROP TABLE IF EXISTS `languages`"); 
    157echo "done<br>\n"; 
    168