Changeset 5328
- Timestamp:
- 12/02/07 00:53:34 (6 years ago)
- Files:
-
- modules/branches/2.4/languages (copied) (copied from modules/branches/2.4/miscapps)
- modules/branches/2.4/languages/functions.inc.php (copied) (copied from modules/branches/2.4/miscapps/functions.inc.php) (5 diffs)
- modules/branches/2.4/languages/install.php (copied) (copied from modules/branches/2.4/miscapps/install.php) (2 diffs)
- modules/branches/2.4/languages/module.xml (copied) (copied from modules/branches/2.4/miscapps/module.xml) (1 diff)
- modules/branches/2.4/languages/page.languages.php (added)
- modules/branches/2.4/languages/uninstall.php (copied) (copied from modules/branches/2.4/miscapps/uninstall.php) (1 diff)
- modules/branches/2.4/miscapps/install.sql (deleted)
- modules/branches/2.4/miscapps/page.miscapps.php (deleted)
- modules/branches/2.4/miscapps/uninstall.sql (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.4/languages/functions.inc.php
r5276 r5328 1 1 <?php 2 2 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) { 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) { 16 36 global $ext; 17 37 switch ($engine) { 18 38 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'])); 26 44 } 27 45 break; … … 29 47 } 30 48 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 35 50 */ 36 function miscapps_list($get_ext = false) {37 global $db; 38 $sql = "SELECT miscapps_id, description, dest FROM miscapps ORDER BY description ";51 function languages_list() { 52 global $db; 53 $sql = "SELECT language_id, description, lang_code, dest FROM languages ORDER BY description "; 39 54 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 40 55 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 } 52 58 return $results; 53 59 } 54 60 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);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); 58 64 $row = $db->getRow($sql, DB_FETCHMODE_ASSOC); 59 65 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"); 61 67 } 62 68 63 // we want to get the ext from featurecodes64 $fc = new featurecode('miscapps', 'miscapp_'.$row['miscapps_id']);65 $row['ext'] = $fc->getDefault();66 $row['enabled'] = $fc->isEnabled();67 68 69 return $row; 69 70 } 70 71 71 function miscapps_add($description, $ext, $dest) {72 global $db; 73 $sql = "INSERT INTO miscapps (description, ext, dest) VALUES (".72 function languages_add($description, $lang_code, $dest) { 73 global $db; 74 $sql = "INSERT INTO languages (description, lang_code, dest) VALUES (". 74 75 "'".addslashes($description)."', ". 75 "'".addslashes($ ext)."', ".76 "'".addslashes($lang_code)."', ". 76 77 "'".addslashes($dest)."')"; 77 78 $result = $db->query($sql); … … 79 80 die_freepbx($result->getMessage().$sql); 80 81 } 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 84 function languages_delete($language_id) { 85 global $db; 86 $sql = "DELETE FROM languages WHERE language_id = ".addslashes($language_id); 96 87 $result = $db->query($sql); 97 88 if(DB::IsError($result)) { 98 89 die_freepbx($result->getMessage().$sql); 99 90 } 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 93 function languages_edit($language_id, $description, $lang_code, $dest) { 94 global $db; 95 $sql = "UPDATE languages SET ". 108 96 "description = '".addslashes($description)."', ". 109 " ext = '".addslashes($ext)."', ".97 "lang_code = '".addslashes($lang_code)."', ". 110 98 "dest = '".addslashes($dest)."' ". 111 "WHERE miscapps_id = ".addslashes($miscapps_id);99 "WHERE language_id = ".addslashes($language_id); 112 100 $result = $db->query($sql); 113 101 if(DB::IsError($result)) { 114 102 die_freepbx($result->getMessage().$sql); 115 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', 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 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; 116 146 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 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 languages_user_update($extdisplay, $langcode); 171 } elseif ($action == "del") { 172 languages_user_del($extdisplay); 173 } 174 } 175 176 function 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 185 function 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 196 function 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 203 function languages_check_destinations($dest=true) { 125 204 global $active_modules; 126 205 … … 129 208 return $destlist; 130 209 } 131 $sql = "SELECT miscapps_id, dest, description FROM miscapps ";210 $sql = "SELECT language_id, dest, description FROM languages "; 132 211 if ($dest !== true) { 133 212 $sql .= "WHERE dest in ('".implode("','",$dest)."')"; … … 135 214 $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC); 136 215 137 $type = isset($active_modules[' miscapps']['type'])?$active_modules['miscapps']['type']:'setup';216 $type = isset($active_modules['languages']['type'])?$active_modules['languages']['type']:'setup'; 138 217 139 218 foreach ($results as $result) { 140 219 $thisdest = $result['dest']; 141 $thisid = $result[' miscapps_id'];220 $thisid = $result['language_id']; 142 221 $destlist[] = array( 143 222 '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), 146 225 ); 147 226 } 148 227 return $destlist; 149 228 } 150 151 229 ?> modules/branches/2.4/languages/install.php
r4767 r5328 2 2 3 3 global $db; 4 global $amp_conf;5 4 6 5 $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 extVARCHAR( 50 ) ,6 $sql = "CREATE TABLE IF NOT EXISTS languages ( 7 language_id INTEGER NOT NULL PRIMARY KEY $autoincrement, 8 lang_code VARCHAR( 50 ) , 10 9 description VARCHAR( 50 ) , 11 10 dest VARCHAR( 255 ) … … 14 13 $check = $db->query($sql); 15 14 if(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"); 35 16 } 36 17 modules/branches/2.4/languages/module.xml
r4924 r5328 1 1 <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> 5 5 <type>setup</type> 6 6 <category>Internal Options & Configuration</category> 7 7 <description> 8 Adds the ability to c reate 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. 9 9 </description> 10 10 <menuitems> 11 < miscapps>Misc Applications</miscapps>11 <languages>Languages</languages> 12 12 </menuitems> 13 13 <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 24 15 </changelog> 25 <location>release/2. 3/miscapps-0.2.3.5.tgz</location>16 <location>release/2.4/languages-0.8.0tgz</location> 26 17 <md5sum>b05759ac4981e263fd4b8606283c7a8a</md5sum> 27 18 </module> modules/branches/2.4/languages/uninstall.php
r4583 r5328 2 2 3 3 global $db; 4 global $amp_conf;5 4 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`"); 5 echo "dropping table languages.."; 6 sql("DROP TABLE IF EXISTS `languages`"); 15 7 echo "done<br>\n"; 16 8
