| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
function 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 |
|
|---|
| 11 |
function languages_getdest($exten) { |
|---|
| 12 |
return array('app-languages,'.$exten.',1'); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
function 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 |
|
|---|
| 35 |
function languages_get_config($engine) { |
|---|
| 36 |
global $ext; |
|---|
| 37 |
switch ($engine) { |
|---|
| 38 |
case 'asterisk': |
|---|
| 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_setlanguage($row['lang_code'])); |
|---|
| 43 |
$ext->add('app-languages',$row['language_id'], '', new ext_goto($row['dest'])); |
|---|
| 44 |
} |
|---|
| 45 |
break; |
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
/** Get a list of all languages |
|---|
| 50 |
*/ |
|---|
| 51 |
function languages_list() { |
|---|
| 52 |
global $db; |
|---|
| 53 |
$sql = "SELECT language_id, description, lang_code, dest FROM languages ORDER BY description "; |
|---|
| 54 |
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC); |
|---|
| 55 |
if(DB::IsError($results)) { |
|---|
| 56 |
die_freepbx($results->getMessage()."<br><br>Error selecting from languages"); |
|---|
| 57 |
} |
|---|
| 58 |
return $results; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
function languages_get($language_id) { |
|---|
| 62 |
global $db; |
|---|
| 63 |
$sql = "SELECT language_id, description, lang_code, dest FROM languages WHERE language_id = ".addslashes($language_id); |
|---|
| 64 |
$row = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 65 |
if(DB::IsError($row)) { |
|---|
| 66 |
die_freepbx($row->getMessage()."<br><br>Error selecting row from languages"); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
return $row; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
function languages_add($description, $lang_code, $dest) { |
|---|
| 73 |
global $db; |
|---|
| 74 |
$sql = "INSERT INTO languages (description, lang_code, dest) VALUES (". |
|---|
| 75 |
"'".addslashes($description)."', ". |
|---|
| 76 |
"'".addslashes($lang_code)."', ". |
|---|
| 77 |
"'".addslashes($dest)."')"; |
|---|
| 78 |
$result = $db->query($sql); |
|---|
| 79 |
if(DB::IsError($result)) { |
|---|
| 80 |
die_freepbx($result->getMessage().$sql); |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
function languages_delete($language_id) { |
|---|
| 85 |
global $db; |
|---|
| 86 |
$sql = "DELETE FROM languages WHERE language_id = ".addslashes($language_id); |
|---|
| 87 |
$result = $db->query($sql); |
|---|
| 88 |
if(DB::IsError($result)) { |
|---|
| 89 |
die_freepbx($result->getMessage().$sql); |
|---|
| 90 |
} |
|---|
| 91 |
} |
|---|
| 92 |
|
|---|
| 93 |
function languages_edit($language_id, $description, $lang_code, $dest) { |
|---|
| 94 |
global $db; |
|---|
| 95 |
$sql = "UPDATE languages SET ". |
|---|
| 96 |
"description = '".addslashes($description)."', ". |
|---|
| 97 |
"lang_code = '".addslashes($lang_code)."', ". |
|---|
| 98 |
"dest = '".addslashes($dest)."' ". |
|---|
| 99 |
"WHERE language_id = ".addslashes($language_id); |
|---|
| 100 |
$result = $db->query($sql); |
|---|
| 101 |
if(DB::IsError($result)) { |
|---|
| 102 |
die_freepbx($result->getMessage().$sql); |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
function 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', 8); |
|---|
| 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', 8); |
|---|
| 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', 8); |
|---|
| 128 |
} |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
function 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(). |
|---|
| 140 |
function 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; |
|---|
| 146 |
|
|---|
| 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 |
|
|---|
| 157 |
function 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 |
if (!isset($GLOBALS['abort']) || $GLOBALS['abort'] !== true) { |
|---|
| 171 |
languages_user_update($extdisplay, $langcode); |
|---|
| 172 |
} |
|---|
| 173 |
} elseif ($action == "del") { |
|---|
| 174 |
languages_user_del($extdisplay); |
|---|
| 175 |
} |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
function languages_user_get($xtn) { |
|---|
| 179 |
global $astman; |
|---|
| 180 |
|
|---|
| 181 |
// Retrieve the language configuraiton from this user from ASTDB |
|---|
| 182 |
$langcode = $astman->database_get("AMPUSER",$xtn."/language"); |
|---|
| 183 |
|
|---|
| 184 |
return $langcode; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
function languages_user_update($ext, $langcode) { |
|---|
| 188 |
global $astman; |
|---|
| 189 |
// Update the settings in ASTDB |
|---|
| 190 |
$astman->database_put("AMPUSER",$ext."/language",$langcode); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
function languages_user_del($ext) { |
|---|
| 194 |
global $astman; |
|---|
| 195 |
|
|---|
| 196 |
// Clean up the tree when the user is deleted |
|---|
| 197 |
$astman->database_deltree("AMPUSER/$ext/language"); |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
function languages_check_destinations($dest=true) { |
|---|
| 201 |
global $active_modules; |
|---|
| 202 |
|
|---|
| 203 |
$destlist = array(); |
|---|
| 204 |
if (is_array($dest) && empty($dest)) { |
|---|
| 205 |
return $destlist; |
|---|
| 206 |
} |
|---|
| 207 |
$sql = "SELECT language_id, dest, description FROM languages "; |
|---|
| 208 |
if ($dest !== true) { |
|---|
| 209 |
$sql .= "WHERE dest in ('".implode("','",$dest)."')"; |
|---|
| 210 |
} |
|---|
| 211 |
$results = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 212 |
|
|---|
| 213 |
$type = isset($active_modules['languages']['type'])?$active_modules['languages']['type']:'setup'; |
|---|
| 214 |
|
|---|
| 215 |
foreach ($results as $result) { |
|---|
| 216 |
$thisdest = $result['dest']; |
|---|
| 217 |
$thisid = $result['language_id']; |
|---|
| 218 |
$destlist[] = array( |
|---|
| 219 |
'dest' => $thisdest, |
|---|
| 220 |
'description' => 'Language Change: '.$result['description'], |
|---|
| 221 |
'edit_url' => 'config.php?display=languages&type='.$type.'&extdisplay='.urlencode($thisid), |
|---|
| 222 |
); |
|---|
| 223 |
} |
|---|
| 224 |
return $destlist; |
|---|
| 225 |
} |
|---|
| 226 |
?> |
|---|