Changeset 10792
- Timestamp:
- 01/02/11 16:57:38 (2 years ago)
- Files:
-
- modules/branches/2.9/endpointman/ENDPOINTMAN_LICENSE.txt (modified) (2 diffs)
- modules/branches/2.9/endpointman/functions.inc.php (modified) (2 diffs)
- modules/branches/2.9/endpointman/includes/abstraction (added)
- modules/branches/2.9/endpointman/includes/abstraction/freepbx.inc (added)
- modules/branches/2.9/endpointman/includes/advanced.inc (modified) (22 diffs)
- modules/branches/2.9/endpointman/includes/ajax_select.php (modified) (4 diffs)
- modules/branches/2.9/endpointman/includes/brand_model_manager.inc (modified) (5 diffs)
- modules/branches/2.9/endpointman/includes/devices_manager.inc (modified) (7 diffs)
- modules/branches/2.9/endpointman/includes/export.php (modified) (1 diff)
- modules/branches/2.9/endpointman/includes/functions.inc (modified) (45 diffs)
- modules/branches/2.9/endpointman/includes/installer.php (modified) (2 diffs)
- modules/branches/2.9/endpointman/includes/popup.php (added)
- modules/branches/2.9/endpointman/includes/rain.error.php (added)
- modules/branches/2.9/endpointman/includes/rain.tpl.class.php (modified) (11 diffs)
- modules/branches/2.9/endpointman/includes/rain.tpl.compile.class.php (modified) (20 diffs)
- modules/branches/2.9/endpointman/includes/template_manager.inc (modified) (3 diffs)
- modules/branches/2.9/endpointman/install.php (modified) (9 diffs)
- modules/branches/2.9/endpointman/install/phonesettings.module (modified) (5 diffs)
- modules/branches/2.9/endpointman/javascript.html.php (added)
- modules/branches/2.9/endpointman/module.xml (modified) (2 diffs)
- modules/branches/2.9/endpointman/popup.html.php (added)
- modules/branches/2.9/endpointman/templates/advanced_settings_iedl.html (deleted)
- modules/branches/2.9/endpointman/templates/advanced_settings_manual_upload.html (deleted)
- modules/branches/2.9/endpointman/templates/advanced_settings_oui.html (deleted)
- modules/branches/2.9/endpointman/templates/advanced_settings_poce.html (deleted)
- modules/branches/2.9/endpointman/templates/advanced_settings_settings.html (deleted)
- modules/branches/2.9/endpointman/templates/advanced_settings_sh_manager.html (deleted)
- modules/branches/2.9/endpointman/templates/advanced_subheader.html (deleted)
- modules/branches/2.9/endpointman/templates/brand_model_manager.html (deleted)
- modules/branches/2.9/endpointman/templates/credits.html (deleted)
- modules/branches/2.9/endpointman/templates/devices_manager.html (deleted)
- modules/branches/2.9/endpointman/templates/freepbx (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_settings_iedl.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_settings_manual_upload.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_settings_oui.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_settings_poce.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_settings_settings.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_settings_sh_manager.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/advanced_subheader.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/alt_config_popup.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/brand_model_manager.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/compiled (added)
- modules/branches/2.9/endpointman/templates/freepbx/credits.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/devices_manager.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/global_footer.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/global_header.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/global_links.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/ajax_req.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery-1.3.2.min.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery.coda-slider-2.0.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery.cookie.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery.easing.1.3.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery.jstree.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/jquery.tools.min.js (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/apple (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/apple/bg.jpg (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/apple/d.png (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/apple/dot_for_ie.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/apple/style.css (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/apple/throbber.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/classic (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/classic/d.png (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/classic/dot_for_ie.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/classic/style.css (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/classic/throbber.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default-rtl (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default-rtl/d.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default-rtl/d.png (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default-rtl/dots.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default-rtl/style.css (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default-rtl/throbber.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default/d.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default/d.png (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default/style.css (added)
- modules/branches/2.9/endpointman/templates/freepbx/javascript/themes/default/throbber.gif (added)
- modules/branches/2.9/endpointman/templates/freepbx/message_box.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/stylesheets (added)
- modules/branches/2.9/endpointman/templates/freepbx/stylesheets/coda-slider-2.0a.css (added)
- modules/branches/2.9/endpointman/templates/freepbx/stylesheets/reset.css (added)
- modules/branches/2.9/endpointman/templates/freepbx/template_editor.html (added)
- modules/branches/2.9/endpointman/templates/freepbx/template_manager.html (added)
- modules/branches/2.9/endpointman/templates/global_footer.html (deleted)
- modules/branches/2.9/endpointman/templates/global_header.html (deleted)
- modules/branches/2.9/endpointman/templates/global_links.html (deleted)
- modules/branches/2.9/endpointman/templates/images/add.png (added)
- modules/branches/2.9/endpointman/templates/images/add_old.png (added)
- modules/branches/2.9/endpointman/templates/images/ajax-loader.gif (added)
- modules/branches/2.9/endpointman/templates/images/black_arrow.png (added)
- modules/branches/2.9/endpointman/templates/images/bullet_minus.png (added)
- modules/branches/2.9/endpointman/templates/images/bullet_plus.png (added)
- modules/branches/2.9/endpointman/templates/images/delete.png (added)
- modules/branches/2.9/endpointman/templates/images/edit.png (added)
- modules/branches/2.9/endpointman/templates/message_box.html (deleted)
- modules/branches/2.9/endpointman/templates/template_editor.html (deleted)
- modules/branches/2.9/endpointman/templates/template_manager.html (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.9/endpointman/ENDPOINTMAN_LICENSE.txt
r10315 r10792 12 12 License. 13 13 14 The Original Code is Endpoint Manager for PBX in a Flash.14 The Original Code is Endpoint Manager for FreePBX. 15 15 16 16 The Initial Developer of the Original Code is Ed Macri and John Mullinix. … … 24 24 Andrew Nagy 25 25 Darren Schreiber 26 Philippe Lindheimer 26 27 27 28 Alternatively, the contents of this file may be used under the terms of modules/branches/2.9/endpointman/functions.inc.php
r10315 r10792 35 35 function endpointman_configpageinit($pagename) { 36 36 global $currentcomponent; 37 endpointman_applyhooks(); 37 38 $display = isset($_REQUEST['display'])?$_REQUEST['display']:null; 39 if($display == "extensions") { 40 global $endpoint; 41 42 $doc_root = $_SERVER["DOCUMENT_ROOT"] ."/admin/modules/endpointman/"; 43 require($doc_root . "includes/functions.inc"); 44 45 $endpoint = new endpointmanager(); 46 ini_set('display_errors', 0); 47 48 endpointman_applyhooks(); 49 } 38 50 } 39 51 function endpointman_applyhooks() { … … 42 54 // Add the 'process' function - this gets called when the page is loaded, to hook into 43 55 // displaying stuff on the page. 44 //$currentcomponent->addguifunc('endpointman_configpageload');56 $currentcomponent->addguifunc('endpointman_configpageload'); 45 57 } 46 58 // This is called before the page is actually displayed, so we can use addguielem(). 47 59 function endpointman_configpageload() { 48 global $currentcomponent ;60 global $currentcomponent, $endpoint, $db; 49 61 50 62 // Init vars from $_REQUEST[] 51 //$action = isset($_REQUEST['action'])?$_REQUEST['action']:null;52 //$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;63 $action = isset($_REQUEST['action'])?$_REQUEST['action']:null; 64 $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 53 65 54 66 // Don't display this stuff it it's on a 'This xtn has been deleted' page. 55 67 if ($action != 'del') { 56 //$section = _('End Point Manager');57 //$msgInvalidLanguage = _('Please enter a valid Lajnguage Code');58 //$currentcomponent->addguielem($section, new gui_textbox('brand', $langcode, _('Language Code'), _('This will cause all messages and voice prompts to use the selected language if installed.'), "!isFilename()", $msgInvalidLanguage, true),9); 59 //$currentcomponent->addguielem($section, "",9);68 $sql = "SELECT mac_id,luid,line FROM endpointman_line_list WHERE ext = '".$extdisplay."' "; 69 $line_info =& $db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 70 if($line_info) { 71 $info = $endpoint->get_phone_info($line_info['mac_id']); 60 72 61 } 73 74 $js = " 75 $.ajaxSetup({ cache: false }); 76 77 $.getJSON(\"config.php?type=tool&quietmode=1&handler=file&module=endpointman&file=ajax_select.html.php&atype=model\",{id: value}, function(j){ 78 var options = ''; 79 for (var i = 0; i < j.length; i++) { 80 options += '<option value=\"' + j[i].optionValue + '\">' + j[i].optionDisplay + '</option>'; 81 } 82 $('#epm_model').html(options); 83 $('#epm_model option:first').attr('selected', 'selected'); 84 $('#epm_temps').html('<option></option>'); 85 $('#epm_temps option:first').attr('selected', 'selected'); 86 $('#epm_line').html('<option></option>'); 87 $('#epm_line option:first').attr('selected', 'selected'); 88 }) 89 "; 90 $currentcomponent->addjsfunc('brand_change(value)', $js); 91 92 $js = " 93 $.ajaxSetup({ cache: false }); 94 $.getJSON('config.php?type=tool&quietmode=1&handler=file&module=endpointman&file=ajax_select.html.php&atype=template2',{id: value}, function(j){ 95 var options = ''; 96 for (var i = 0; i < j.length; i++) { 97 options += '<option value=\"' + j[i].optionValue + '\">' + j[i].optionDisplay + '</option>'; 98 } 99 $('#epm_temps').html(options); 100 $('#epm_temps option:first').attr('selected', 'selected'); 101 }), 102 $.ajaxSetup({ cache: false }); 103 $.getJSON('config.php?type=tool&quietmode=1&handler=file&module=endpointman&file=ajax_select.html.php&macid='+ macid +'&atype=lines',{id: value}, function(j){ 104 var options = ''; 105 for (var i = 0; i < j.length; i++) { 106 options += '<option value=\"' + j[i].optionValue + '\">' + j[i].optionDisplay + '</option>'; 107 } 108 $('#epm_line').html(options); 109 $('#epm_line option:first').attr('selected', 'selected'); 110 }) 111 "; 112 $currentcomponent->addjsfunc('model_change(value,macid)', $js); 113 114 $section = _('End Point Manager'); 115 116 117 $brand_list = $endpoint->brands_available($info['brand_id'], true); 118 if(!empty($info['brand_id'])) { 119 $model_list = $endpoint->models_available(NULL,$info['brand_id']); 120 $line_list = $endpoint->linesAvailable($line_info['luid']); 121 $template_list = $endpoint->display_templates($info['product_id']); 122 } else { 123 $model_list = array(); 124 $line_list = array(); 125 $template_list = array(); 126 } 127 128 $currentcomponent->addguielem($section, new gui_textbox('epm_mac', $info['mac'], 'MAC Address', 'The MAC Address of the Phone Assigned to this Extension/Device.', 'isEmpty()', 'Please enter a valid MAC Address', true, 12, true),9); 129 $currentcomponent->addguielem($section, new gui_selectbox('epm_brand', $brand_list, $info['brand_id'], 'Brand', 'The Brand of this Phone.', false, 'frm_extensions_brand_change(this.options[this.selectedIndex].value)', false),9); 130 $currentcomponent->addguielem($section, new gui_selectbox('epm_model', $model_list, $info['model_id'], 'Model', 'The Model of this Phone.', false, 'frm_extensions_model_change(this.options[this.selectedIndex].value,\''.$line_info['luid'].'\')', false),9); 131 $currentcomponent->addguielem($section, new gui_selectbox('epm_line', $line_list, $line_info['line'], 'Line', 'The Line of this Extension/Device.', false, '', false),9); 132 $currentcomponent->addguielem($section, new gui_selectbox('epm_temps', $template_list, $info['template_id'], 'Template', 'The Template of this Phone.', false, '', false),9); 133 } 134 } 62 135 } 63 136 modules/branches/2.9/endpointman/includes/advanced.inc
r10315 r10792 8 8 */ 9 9 10 $tpl = new RainTPL( LOCAL_PATH.'templates' );11 10 //Set the message variable to nothing, however we can set it later and it will show up on the page 12 11 $message = NULL; 13 $tpl->assign("message", $message); 14 $tpl->assign("web_vars", "?type=$type"); 15 16 echo $tpl->draw( 'global_header' ); 12 $error_message = NULL; 13 $endpoint->tpl->assign("message", $message); 14 $endpoint->tpl->assign("web_vars", "?type=$type"); 15 16 echo $endpoint->tpl->draw( 'global_header' ); 17 17 if(!isset($_REQUEST['subpage'])) { 18 18 $_REQUEST['subpage'] = ""; 19 $ tpl->assign("subhead_area", 'settings');19 $endpoint->tpl->assign("subhead_area", 'settings'); 20 20 } else { 21 $ tpl->assign("subhead_area", $_REQUEST['subpage']);21 $endpoint->tpl->assign("subhead_area", $_REQUEST['subpage']); 22 22 } 23 echo $ tpl->draw( 'advanced_subheader' );23 echo $endpoint->tpl->draw( 'advanced_subheader' ); 24 24 25 25 … … 27 27 switch($_REQUEST['subpage']) { 28 28 case "iedl": 29 $ tpl->assign("exporter_address", "config.php?type=tool&display=epm_config&quietmode=1&handler=file&file=export.html.php&module=endpointman&rand=".rand());29 $endpoint->tpl->assign("exporter_address", "config.php?type=tool&display=epm_config&quietmode=1&handler=file&file=export.html.php&module=endpointman&rand=".rand()); 30 30 //Dave B's Q&D file upload security code (http://us2.php.net/manual/en/features.file-upload.php) 31 31 if((isset($_REQUEST['action'])) AND (isset($_REQUEST['button_import'])) AND ($_REQUEST['action'] == "import")) { … … 34 34 if ($file['tmp_name'] > '') { 35 35 if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { 36 $ tpl->assign("message", "We support only CVS and TXT files");36 $endpoint->tpl->assign("message", "We support only CVS and TXT files"); 37 37 } else { 38 38 $uploaddir = LOCAL_PATH; … … 54 54 $sql_ext = "SELECT extension, name FROM users WHERE extension LIKE '%".$device[3]."%' LIMIT 1"; 55 55 56 $res_model =& $db->query($sql_model); 56 if(isset($device[4])) { 57 $line_id = $device[4]; 58 } else { 59 $line_id = 1; 60 } 61 62 $res_model =& $endpoint->db->query($sql_model); 57 63 if($res_model->numRows()) { 58 $model_id =& $ db->getRow($sql_model,array(), DB_FETCHMODE_ASSOC);64 $model_id =& $endpoint->db->getRow($sql_model,array(), DB_FETCHMODE_ASSOC); 59 65 $model_id = $model_id['id']; 60 66 61 $res_ext =& $ db->query($sql_ext);67 $res_ext =& $endpoint->db->query($sql_ext); 62 68 if($res_ext->numRows()) { 63 $ext =& $ db->getRow($sql_ext,array(), DB_FETCHMODE_ASSOC);69 $ext =& $endpoint->db->getRow($sql_ext,array(), DB_FETCHMODE_ASSOC); 64 70 $description = $ext['name']; 65 71 $ext = $ext['extension']; 66 72 67 $sql = "INSERT INTO endpointman_mac_list (mac, model) VALUES ('".$mac."','".$model_id."')"; 73 $sql_mac = "SELECT id FROM endpointman_mac_list WHERE mac = '".$mac."'"; 74 $res_mac =& $endpoint->db->query($sql_mac); 75 if($res_mac->numRows()) { 76 $ext_id = $endpoint->db->getOne($sql_mac); 77 } else { 78 $sql = "INSERT INTO endpointman_mac_list (mac, model) VALUES ('".$mac."','".$model_id."')"; 79 $endpoint->db->query($sql); 80 81 $sql = 'SELECT last_insert_id()'; 82 $ext_id =& $endpoint->db->getOne($sql); 83 } 84 85 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$ext_id."', '".$ext."', '".$line_id."','".$description."')"; 68 86 $endpoint->db->query($sql); 69 87 70 $sql = 'SELECT last_insert_id()'; 71 $ext_id =& $endpoint->db->getOne($sql); 72 73 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$ext_id."', '".$ext."', '1','".$description."')"; 74 $endpoint->db->query($sql); 75 76 $message .= "Inserted Mac Address ".$mac."<br/>"; 88 $message .= "Inserted Mac Address: ".$mac." & Line: ".$line_id."<br/>"; 77 89 } else { 78 90 $endpoint->error['csv_upload'] = 'Invalid Extension Specified'; … … 110 122 } 111 123 if(isset($message)) { 112 $endpoint->display_message_box($message,$ tpl,0);124 $endpoint->display_message_box($message,$endpoint->tpl,0); 113 125 } 114 126 if(isset($error_message)) { 115 $endpoint->display_message_box($error_message,$ tpl,1);116 } 117 echo $ tpl->draw( 'advanced_settings_iedl' );127 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 128 } 129 echo $endpoint->tpl->draw( 'advanced_settings_iedl' ); 118 130 break; 119 131 case "manual_upload": … … 121 133 $provisioner_ver = $endpoint->db->getOne($sql); 122 134 $provisioner_ver = date("n-j-y",$provisioner_ver) . " at " . date("g:ia",$provisioner_ver); 123 $ tpl->assign("provisioner_ver", $provisioner_ver);135 $endpoint->tpl->assign("provisioner_ver", $provisioner_ver); 124 136 125 137 //$provisioner_ver = filemtime(PHONE_MODULES_PATH."master.xml"); 126 138 //$provisioner_ver = date("n-j-y",$provisioner_ver) . " at " . date("g:ia",$provisioner_ver); 127 139 $provisioner_ver = ""; 128 $ tpl->assign("master_ver", $provisioner_ver);140 $endpoint->tpl->assign("master_ver", $provisioner_ver); 129 141 $uploads_dir = PHONE_MODULES_PATH."temp"; 130 142 … … 137 149 $name = $_FILES["package"]["name"]; 138 150 move_uploaded_file($tmp_name, "$uploads_dir/$name"); 139 $ tpl->assign("show_installer", 1);140 $ tpl->assign("package", $name);141 $ tpl->assign("type", "upload_provisioner");142 $ tpl->assign("xml", 0);151 $endpoint->tpl->assign("show_installer", 1); 152 $endpoint->tpl->assign("package", $name); 153 $endpoint->tpl->assign("type", "upload_provisioner"); 154 $endpoint->tpl->assign("xml", 0); 143 155 } else { 144 156 $endpoint->error['manual_upload'] = $endpoint->file_upload_error_message($_FILES['package']['error']); … … 156 168 $name = $_FILES['xml']["name"]; 157 169 move_uploaded_file($tmp_name, "$uploads_dir/$name"); 158 $ tpl->assign("show_installer", 1);159 $ tpl->assign("package", 0);160 $ tpl->assign("type", "upload_master_xml");161 $ tpl->assign("xml", $name);170 $endpoint->tpl->assign("show_installer", 1); 171 $endpoint->tpl->assign("package", 0); 172 $endpoint->tpl->assign("type", "upload_master_xml"); 173 $endpoint->tpl->assign("xml", $name); 162 174 } else { 163 175 $endpoint->error['manual_upload'] = $endpoint->file_upload_error_message($_FILES['xml']['error']); … … 189 201 } 190 202 if(!$error){ 191 $ tpl->assign("show_installer", 1);192 $ tpl->assign("package", $files_list[1]);193 $ tpl->assign("type", "upload_brand");194 $ tpl->assign("xml", $files_list[0]);203 $endpoint->tpl->assign("show_installer", 1); 204 $endpoint->tpl->assign("package", $files_list[1]); 205 $endpoint->tpl->assign("type", "upload_brand"); 206 $endpoint->tpl->assign("xml", $files_list[0]); 195 207 } else { 196 208 $message = $error_message; … … 207 219 } 208 220 if(isset($message)) { 209 $endpoint->display_message_box($message,$ tpl,0);221 $endpoint->display_message_box($message,$endpoint->tpl,0); 210 222 } 211 223 if(isset($error_message)) { 212 $endpoint->display_message_box($error_message,$ tpl,1);213 } 214 215 echo $ tpl->draw( 'advanced_settings_manual_upload' );224 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 225 } 226 227 echo $endpoint->tpl->draw( 'advanced_settings_manual_upload' ); 216 228 break; 217 229 case "sh_manager": … … 260 272 $i++; 261 273 } 262 $ tpl->assign("brand2_list", $row_out);263 echo $ tpl->draw( 'advanced_settings_sh_manager' );274 $endpoint->tpl->assign("brand2_list", $row_out); 275 echo $endpoint->tpl->draw( 'advanced_settings_sh_manager' ); 264 276 break; 265 277 case "oui_manager": … … 280 292 $i++; 281 293 } 282 $ tpl->assign("oui_list", $row_out);294 $endpoint->tpl->assign("oui_list", $row_out); 283 295 $sql = 'SELECT endpointman_oui_list.id, endpointman_oui_list.oui , endpointman_brand_list.name FROM endpointman_oui_list , endpointman_brand_list WHERE endpointman_oui_list.brand = endpointman_brand_list.id AND endpointman_oui_list.custom = 1'; 284 296 $data =& $endpoint->db->getAll($sql, array(), DB_FETCHMODE_ASSOC); … … 289 301 $i++; 290 302 } 291 $ tpl->assign("oui_list_custom", $row_out_custom);292 $ tpl->assign("brand_ava", $endpoint->brandAvailable());303 $endpoint->tpl->assign("oui_list_custom", $row_out_custom); 304 $endpoint->tpl->assign("brand_ava", $endpoint->brands_available()); 293 305 294 306 $error_message = NULL; … … 301 313 } 302 314 if(isset($message)) { 303 $endpoint->display_message_box($message,$ tpl,0);315 $endpoint->display_message_box($message,$endpoint->tpl,0); 304 316 } 305 317 if(isset($error_message)) { 306 $endpoint->display_message_box($error_message,$ tpl,1);307 } 308 309 echo $ tpl->draw( 'advanced_settings_oui' );318 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 319 } 320 321 echo $endpoint->tpl->draw( 'advanced_settings_oui' ); 310 322 break; 311 323 case "poce": … … 363 375 $contents = fread($handle, filesize($file)); 364 376 fclose($handle); 365 $ tpl->assign("location", $file);366 $ tpl->assign("config_data", $contents);377 $endpoint->tpl->assign("location", $file); 378 $endpoint->tpl->assign("config_data", $contents); 367 379 } 368 380 if(isset($_REQUEST['file'])) { … … 394 406 } 395 407 396 $ tpl->assign("save_as_name_value", $config_files[$_REQUEST['file']]);397 $ tpl->assign("config_data", $contents);398 $ tpl->assign("filename", $config_files[$_REQUEST['file']]);399 $ tpl->assign('sendid', $_REQUEST['file']);400 $ tpl->assign("type", 'file');401 $ tpl->assign("location", $file);408 $endpoint->tpl->assign("save_as_name_value", $config_files[$_REQUEST['file']]); 409 $endpoint->tpl->assign("config_data", $contents); 410 $endpoint->tpl->assign("filename", $config_files[$_REQUEST['file']]); 411 $endpoint->tpl->assign('sendid', $_REQUEST['file']); 412 $endpoint->tpl->assign("type", 'file'); 413 $endpoint->tpl->assign("location", $file); 402 414 403 415 } elseif(isset($_REQUEST['sql'])) { … … 424 436 $sql = 'SELECT * FROM endpointman_custom_configs WHERE id =' . $_REQUEST['sql']; 425 437 $row =& $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 426 $ tpl->assign("save_as_name_value", $row['name']);427 $ tpl->assign("filename", $row['original_name']);428 $ tpl->assign('sendid', $_REQUEST['sql']);429 $ tpl->assign("type", 'sql');430 $ tpl->assign("config_data", $row['data']);438 $endpoint->tpl->assign("save_as_name_value", $row['name']); 439 $endpoint->tpl->assign("filename", $row['original_name']); 440 $endpoint->tpl->assign('sendid', $_REQUEST['sql']); 441 $endpoint->tpl->assign("type", 'sql'); 442 $endpoint->tpl->assign("config_data", $row['data']); 431 443 } 432 444 if(isset($_REQUEST['product_select'])) { … … 464 476 if((method_exists($phone_config,'display_options')) AND (method_exists($phone_config,'process_options'))) { 465 477 if(isset($_REQUEST['phone_options'])) { 466 $ tpl->assign("options", $phone_config->process_options());478 $endpoint->tpl->assign("options", $phone_config->process_options()); 467 479 } else { 468 $ tpl->assign("options", $phone_config->display_options());480 $endpoint->tpl->assign("options", $phone_config->display_options()); 469 481 } 470 482 } … … 483 495 } 484 496 485 $ tpl->assign("template_file_list",$template_file_list);497 $endpoint->tpl->assign("template_file_list",$template_file_list); 486 498 if(isset($_REQUEST['temp_file'])) { 487 $ tpl->assign("temp_file",1);488 } else { 489 $ tpl->assign("temp_file",NULL);490 } 491 492 $ tpl->assign("file_list", $file_list);493 $ tpl->assign("sql_file_list", $sql_file_list);494 $ tpl->assign("product_selected", $_REQUEST['product_select']);495 } 496 $ tpl->assign("product_list", $product_list);499 $endpoint->tpl->assign("temp_file",1); 500 } else { 501 $endpoint->tpl->assign("temp_file",NULL); 502 } 503 504 $endpoint->tpl->assign("file_list", $file_list); 505 $endpoint->tpl->assign("sql_file_list", $sql_file_list); 506 $endpoint->tpl->assign("product_selected", $_REQUEST['product_select']); 507 } 508 $endpoint->tpl->assign("product_list", $product_list); 497 509 498 510 $error_message = NULL; … … 505 517 } 506 518 if(isset($message)) { 507 $endpoint->display_message_box($message,$ tpl,0);519 $endpoint->display_message_box($message,$endpoint->tpl,0); 508 520 } 509 521 if(isset($error_message)) { 510 $endpoint->display_message_box($error_message,$ tpl,1);511 } 512 513 echo $ tpl->draw( 'advanced_settings_poce' );522 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 523 } 524 525 echo $endpoint->tpl->draw( 'advanced_settings_poce' ); 514 526 break; 515 527 case "settings": … … 618 630 global $debug; 619 631 $debug = $debug . print_r($_REQUEST,true); 620 $ tpl->assign("debug", $debug);632 $endpoint->tpl->assign("debug", $debug); 621 633 } else { 622 634 $debug_selected = ""; 623 635 } 624 $ tpl->assign("htaccess_selected", $htaccess_selected);625 $ tpl->assign("ari_selected", $ari_selected);626 $ tpl->assign("updates_selected", $updates_selected);627 $ tpl->assign("debug_selected", $debug_selected);628 629 $ tpl->assign("ip", $_SERVER["SERVER_ADDR"]);630 $ tpl->assign("srvip", $endpoint->global_cfg['srvip']);631 $ tpl->assign("arp_location", $endpoint->global_cfg['arp_location']);632 $ tpl->assign("nmap_location", $endpoint->global_cfg['nmap_location']);633 $ tpl->assign("asterisk_location", $endpoint->global_cfg['asterisk_location']);634 635 $ tpl->assign("config_location", $endpoint->global_cfg['config_location']);636 $ tpl->assign("list_tz", $endpoint->listTZ($endpoint->global_cfg['tz']));637 $ tpl->assign("brand_list", $endpoint->brandAvailable());636 $endpoint->tpl->assign("htaccess_selected", $htaccess_selected); 637 $endpoint->tpl->assign("ari_selected", $ari_selected); 638 $endpoint->tpl->assign("updates_selected", $updates_selected); 639 $endpoint->tpl->assign("debug_selected", $debug_selected); 640 641 $endpoint->tpl->assign("ip", $_SERVER["SERVER_ADDR"]); 642 $endpoint->tpl->assign("srvip", $endpoint->global_cfg['srvip']); 643 $endpoint->tpl->assign("arp_location", $endpoint->global_cfg['arp_location']); 644 $endpoint->tpl->assign("nmap_location", $endpoint->global_cfg['nmap_location']); 645 $endpoint->tpl->assign("asterisk_location", $endpoint->global_cfg['asterisk_location']); 646 647 $endpoint->tpl->assign("config_location", $endpoint->global_cfg['config_location']); 648 $endpoint->tpl->assign("list_tz", $endpoint->listTZ($endpoint->global_cfg['tz'])); 649 $endpoint->tpl->assign("brand_list", $endpoint->brands_available()); 638 650 639 651 $error_message = NULL; … … 646 658 } 647 659 if(isset($message)) { 648 $endpoint->display_message_box($message,$ tpl,0);660 $endpoint->display_message_box($message,$endpoint->tpl,0); 649 661 } 650 662 if(isset($error_message)) { 651 $endpoint->display_message_box($error_message,$ tpl,1);652 } 653 654 echo $ tpl->draw( 'advanced_settings_settings' );663 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 664 } 665 666 echo $endpoint->tpl->draw( 'advanced_settings_settings' ); 655 667 break; 656 668 } modules/branches/2.9/endpointman/includes/ajax_select.php
r10240 r10792 8 8 */ 9 9 include 'jsonwrapper.php'; 10 //ini_set('display_errors', 1); 11 function in_array_recursive($needle, $haystack) { 12 13 $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($haystack)); 14 15 foreach($it AS $element) { 16 if($element == $needle) { 17 return TRUE; 18 } 19 } 20 return FALSE; 21 } 22 23 function linesAvailable($lineid=NULL,$macid=NULL) { 24 global $db; 25 if(isset($lineid)) { 26 $sql="SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT endpointman_mac_list.model FROM endpointman_mac_list, endpointman_line_list WHERE endpointman_line_list.luid = ".$lineid." AND endpointman_line_list.mac_id = endpointman_mac_list.id)"; 27 28 $sql_l = "SELECT line, mac_id FROM `endpointman_line_list` WHERE luid = ".$lineid; 29 $line =& $db->getRow($sql_l, array(), DB_FETCHMODE_ASSOC); 30 31 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = ".$line['mac_id']; 32 } elseif(isset($macid)) { 33 $sql="SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT model FROM endpointman_mac_list WHERE id =".$macid.")"; 34 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = ".$macid; 35 36 $line['line'] = 0; 37 } 38 $max_lines = $db->getOne($sql); 39 $lines_used =& $db->getAll($sql_lu); 40 41 for($i = 1; $i <= $max_lines; $i++) { 42 if($i == $line['line']) { 43 $temp[$i]['value'] = $i; 44 $temp[$i]['text'] = $i; 45 $temp[$i]['selected'] = "selected"; 46 } else { 47 if(!in_array_recursive($i,$lines_used)) { 48 $temp[$i]['value'] = $i; 49 $temp[$i]['text'] = $i; 50 } 51 } 52 } 53 if(isset($temp)) { 54 return($temp); 55 } else { 56 return FALSE; 57 } 58 } 10 59 11 60 if(($_REQUEST['id'] == "") OR ($_REQUEST['id'] == "0")) { … … 25 74 $sql = "SELECT endpointman_model_list.id, endpointman_model_list.model as model FROM endpointman_model_list, endpointman_product_list WHERE endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_model_list.enabled = 1 AND endpointman_model_list.hidden = 0 AND product_id = '". $_GET['id']."'"; 26 75 } elseif ($_REQUEST['atype'] == "lines") { 27 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = '". $_GET['id']."'"; 76 if(isset($_REQUEST['macid'])) { 77 //die(); 78 $sql = "SELECT endpointman_model_list.max_lines FROM endpointman_model_list,endpointman_line_list,endpointman_mac_list WHERE endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_line_list.luid = ". $_REQUEST['macid']; 79 } else { 80 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = '". $_GET['id']."'"; 81 } 28 82 } 29 83 … … 40 94 } 41 95 42 if( $_REQUEST['atype'] == "lines") {96 if(($_REQUEST['atype'] == "lines") && (!isset($_REQUEST['macid']))) { 43 97 $count = $db->getOne($sql); 44 98 for($z=0;$z<$count;$z++) { … … 46 100 $result[$z]['model'] = $z + 1; 47 101 } 102 } elseif(isset($_REQUEST['macid'])) { 103 $result = linesAvailable($_REQUEST['macid']); 48 104 } else { 49 105 $result = $db->getAll($sql,array(), DB_FETCHMODE_ASSOC); 50 106 } 51 107 52 53 108 foreach($result as $row) { 54 $out[$i]['optionValue'] = $row['id']; 55 $out[$i]['optionDisplay'] = $row['model']; 109 if(isset($_REQUEST['macid'])) { 110 $out[$i]['optionValue'] = $row['value']; 111 $out[$i]['optionDisplay'] = $row['text']; 112 } else { 113 $out[$i]['optionValue'] = $row['id']; 114 $out[$i]['optionDisplay'] = $row['model']; 115 } 56 116 $i++; 57 117 } 58 118 119 59 120 echo json_encode($out); modules/branches/2.9/endpointman/includes/brand_model_manager.inc
r10315 r10792 11 11 global $type; 12 12 13 //initialize a Rain TPL object14 $tpl = new RainTPL( LOCAL_PATH.'templates' );15 16 13 if((isset($_REQUEST['button_install'])) OR (isset($_REQUEST['button_update']))) { 17 14 if(isset($_REQUEST['brand'])) { … … 24 21 $endpoint->remove_firmware($_REQUEST['product']); 25 22 $installer = array("type" => 'firmware', "id" => $_REQUEST['product']); 23 } elseif(isset($_REQUEST['button_remove_firmware'])) { 24 $endpoint->remove_firmware($_REQUEST['product']); 25 $message = "Firmware Removed"; 26 26 } 27 } elseif((isset($_REQUEST['button_remove_firmware'])) AND (isset($_REQUEST['product']))) {28 $endpoint->remove_firmware($_REQUEST['product']);29 27 } elseif(isset($_REQUEST['button_disable'])) { 30 28 if(isset($_REQUEST['model'])) { … … 47 45 } elseif(isset($_REQUEST['button_check_for_updates'])) { 48 46 $brand_up = $endpoint->brand_update_check(); 49 $ tpl->assign("update_check", 1);47 $endpoint->tpl->assign("update_check", 1); 50 48 51 49 $check_for_updates = TRUE; … … 127 125 128 126 if (isset($installer)) { 129 $ tpl->assign("brand", $brand);130 $ tpl->assign("installer", $installer);127 $endpoint->tpl->assign("brand", $brand); 128 $endpoint->tpl->assign("installer", $installer); 131 129 } 132 130 133 $ tpl->assign("web_var", "?type=$type");134 $ tpl->assign("brand2_list", $row_out);131 $endpoint->tpl->assign("web_var", "?type=$type"); 132 $endpoint->tpl->assign("brand2_list", $row_out); 135 133 136 134 $error_message = NULL; … … 143 141 } 144 142 if(isset($error_message)) { 145 $endpoint->display_message_box($error_message,$tpl,1); 143 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 144 } elseif(isset($message)) { 145 $endpoint->display_message_box($message,$endpoint->tpl,0); 146 146 } 147 147 148 148 //draw the template 149 echo $ tpl->draw( 'brand_model_manager' );149 echo $endpoint->tpl->draw( 'brand_model_manager' ); modules/branches/2.9/endpointman/includes/devices_manager.inc
r10315 r10792 3 3 * Endpoint Manager Devices Manager File 4 4 * 5 * BLEEEECKKKKKK, There I just puked all over this file. That's basically what it looks like in terms of code. 6 * It's a hacked-together POS written by me (Andrew) and I really need to fix it ASAP!! ah! 7 * 5 8 * @author Andrew Nagy 6 9 * @license MPL / GPLv2 / LGPL 7 10 * @package Provisioner 11 * 8 12 */ 9 13 … … 11 15 $message = NULL; 12 16 $error_message = NULL; 13 14 15 17 $no_add = FALSE; 16 18 $final = NULL; … … 20 22 $mode = NULL; 21 23 22 $family_list =& $endpoint->db->getAll("SELECT * FROM endpointman_product_list WHERE id > 0",array(),DB_FETCHMODE_ASSOC); 23 24 $mac_list =& $endpoint->db->getAll("SELECT * FROM endpointman_mac_list",array(),DB_FETCHMODE_ASSOC); 25 26 if((!$family_list) && (!$mac_list)) { 24 $family_list =& $endpoint->endpoint_data->all_products(); 25 $full_device_list =& $endpoint->endpoint_data->all_devices(); 26 27 if((!$family_list) && (!$full_device_list)) { 27 28 $message = _("Welcome to Endpoint Manager")."!<br />"._("You have no products (Modules) installed, click")." <a href=\"config.php?display=epm_config&type=$type\">"._("here")."</a> "._("to install some"); 28 29 $no_add = TRUE; … … 35 36 } 36 37 37 if(isset($_REQUEST['button_add'])) { 38 if($mac = $endpoint->mac_check_clean($_REQUEST['mac'])) { 39 $sql = 'SELECT description FROM devices WHERE id = '.$_REQUEST['ext_list']; 40 $name =& $endpoint->db->getOne($sql); 41 42 $endpoint->sync_model($_REQUEST['model_list']); 43 44 $sql = 'SELECT endpointman_product_list. * , endpointman_model_list.template_data, endpointman_brand_list.directory FROM endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_model_list.id = \''.$_REQUEST['model_list'].'\' AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id'; 45 46 $row =& $endpoint->db->getRow($sql,array(),DB_FETCHMODE_ASSOC); 47 48 $cfg_data = unserialize($row['template_data']); 49 50 $count = count($cfg_data); 51 $i = 0; 52 while($i < $count) { 53 if(array_key_exists('variable',$cfg_data[$i])) { 54 $temping = str_replace('$','',$cfg_data[$i]['variable']); 55 if(is_array($cfg_data[$i]['default_value'])) { 56 $custom_cfg_data[$temping]['value'] = ''; 38 if((isset($_REQUEST['sub_type'])) AND (!$no_add)) { 39 $sub_type = $_REQUEST['sub_type']; 40 if(isset($_REQUEST['sub_type_sub'])) { 41 $sub_type_sub = $_REQUEST['sub_type_sub']; 42 } else { 43 $sub_type_sub = ""; 44 } 45 } else { 46 $sub_type = ""; 47 } 48 49 switch ($sub_type) { 50 //Edit Mode 51 case "edit": 52 switch ($sub_type_sub) { 53 case "add_line_x": 54 $_REQUEST['id'] = $_REQUEST['edit_id']; 55 if($endpoint->linesAvailable(NULL,$_REQUEST['id'])) { 56 if($endpoint->endpoint_data->all_unused_registrations()) { 57 $sql = 'SELECT * FROM `endpointman_line_list` WHERE `mac_id` = '. $_REQUEST['id']; 58 $lines_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 59 60 foreach($lines_list as $row) { 61 $sql = "SELECT description FROM devices WHERE id = ".$_REQUEST['ext_list_'.$row['luid']]; 62 $name=$endpoint->db->getOne($sql); 63 64 $sql = "UPDATE endpointman_line_list SET line = '".$_REQUEST['line_list_'.$row['luid']]."', ext = ".$_REQUEST['ext_list_'.$row['luid']].", description = '".$name."' WHERE luid = ". $row['luid']; 65 $endpoint->db->query($sql); 66 } 67 68 $reg = array_values($endpoint->display_registration_list()); 69 $lines = array_values($endpoint->linesAvailable(NULL,$_REQUEST['id'])); 70 71 $sql = "SELECT description FROM devices WHERE id = ".$reg[0]['value']; 72 $name=$endpoint->db->getOne($sql); 73 74 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$_REQUEST['id']."', '".$reg[0]['value']."', '".$lines[0]['value']."', '".$name."')"; 75 $endpoint->db->query($sql); 76 $message = "Configuration Files will not be Generated until you click Save!"; 77 } else { 78 $message = _("No Devices/Extensions Left to Add")."!"; 79 } 57 80 } else { 58 $custom_cfg_data[$temping]['value'] = $cfg_data[$i]['default_value']; 59 } 60 } 61 $i++; 62 } 63 if(is_array($custom_cfg_data)) { 64 $custom_cfg_data = serialize($custom_cfg_data); 65 } else { 66 $temp = array(); 67 $custom_cfg_data = serialize($temp); 68 } 69 70 $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `global_custom_cfg_data`, `template_id`) VALUES ('".$mac."', '".$_REQUEST['model_list']."', '".$custom_cfg_data."', '".$_REQUEST['template_list']."')"; 71 $endpoint->db->query($sql); 72 73 $sql = 'SELECT last_insert_id()'; 74 $ext_id =& $endpoint->db->getOne($sql); 75 76 if(!isset($_REQUEST['line_list'])) { 77 $_REQUEST['line_list'] = 1; 78 } 79 80 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$ext_id."', '".$_REQUEST['ext_list']."', '".$_REQUEST['line_list']."', '".$name."')"; 81 $endpoint->db->query($sql); 82 83 $mac_id = $endpoint->get_phone_info($ext_id); 84 85 $endpoint->prepare_configs($mac_id); 86 87 $message = _("Saved")."!"; 88 } else { 89 $message = _("Invalid MAC Address")."!"; 90 } 91 } elseif(isset($_REQUEST['editready'])) { 92 $edit_row=$endpoint->get_phone_info($_REQUEST['id']); 93 $edit_row['id'] = $_REQUEST['id']; 94 $mode = "EDIT"; 95 } elseif(isset($_REQUEST['button_edit'])) { 96 97 if(empty($_REQUEST['edit_id'])) { 98 $message = _("No Device Selected to Edit!")."!"; 99 } else { 100 $template_editor = TRUE; 101 $sql = "UPDATE endpointman_mac_list SET model = '".$_REQUEST['model_list']."' WHERE id =".$_REQUEST['edit_id']; 102 $endpoint->db->query($sql); 103 if ($_REQUEST['template_list'] == 0) { 104 $endpoint->edit_template_display($_REQUEST['edit_id'],1); 105 } else { 106 $endpoint->edit_template_display($_REQUEST['template_list'],0); 107 } 108 } 109 } elseif(isset($_REQUEST['button_save'])) { 110 $sql = "SELECT description FROM devices WHERE id = ".$_REQUEST['ext_list']; 111 $name=$endpoint->db->getOne($sql); 112 113 $sql = "UPDATE endpointman_mac_list SET template_id = '".$_REQUEST['template_list']."', model = '".$_REQUEST['model_list']."' WHERE id = ". $_REQUEST['edit_id']; 114 $endpoint->db->query($sql); 115 116 $sql = "UPDATE endpointman_line_list SET ext = ".$_REQUEST['ext_list'].", description = '".$name."' WHERE mac_id = ". $_REQUEST['edit_id']; 117 $endpoint->db->query($sql); 118 119 $row = $endpoint->get_phone_info($_REQUEST['edit_id']); 120 121 $endpoint->prepare_configs($row); 122 123 $message = _("Saved")."!"; 124 } elseif(isset($_REQUEST['deleteready'])) { 125 $row = $endpoint->get_phone_info($_REQUEST['id']); 126 127 $sql = "DELETE FROM endpointman_mac_list WHERE id=".$_REQUEST['id']; 128 $endpoint->db->query($sql); 129 $sql = "DELETE FROM endpointman_line_list WHERE mac_id=".$_REQUEST['id']; 130 $endpoint->db->query($sql); 131 $message = _("Deleted")."!"; 132 } elseif((isset($_REQUEST['button_add_selected_phones'])) AND (isset($_REQUEST['add']))) { 133 $list_num = count($_REQUEST['add']); 134 for($i=0;$i<$list_num;$i++) { 135 $num = $_REQUEST['add'][$i]; 136 if($mac = $endpoint->mac_check_clean($_REQUEST['mac_'.$num])) { 137 $sql = "SELECT * FROM endpointman_line_list WHERE ext = ".$_REQUEST['ext_list_'.$num]; 138 $res =& $endpoint->db->query($sql); 139 $count_macs = $res->numRows(); 140 if(!$count_macs) { 141 $sql = 'SELECT `name` FROM `users` WHERE `extension` = '.$_REQUEST['ext_list_'.$num]; 142 $name =& $endpoint->db->getOne($sql,array(),DB_FETCHMODE_ASSOC); 143 144 145 //$sql = 'SELECT endpointman_product_list. * , endpointman_brand_list.directory FROM endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_model_list.id = \''.$_REQUEST['model_list_'.$num].'\' AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id'; 146 //$row =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 147 148 149 $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `template_id`) VALUES ('".$mac."', '".$_REQUEST['model_list_'.$num]."', '0')"; 81 $message = _("No Lines Left to Add")."!"; 82 } 83 break; 84 case "button_edit": 85 if(empty($_REQUEST['edit_id'])) { 86 $message = _("No Device Selected to Edit!")."!"; 87 } else { 88 $template_editor = TRUE; 89 $sql = "UPDATE endpointman_mac_list SET model = '".$_REQUEST['model_list']."' WHERE id =".$_REQUEST['edit_id']; 90 $endpoint->db->query($sql); 91 if ($_REQUEST['template_list'] == 0) { 92 $endpoint->edit_template_display($_REQUEST['edit_id'],1); 93 } else { 94 $endpoint->edit_template_display($_REQUEST['template_list'],0); 95 } 96 } 97 break; 98 case "button_save": 99 $sql = 'SELECT * FROM endpointman_line_list WHERE mac_id = '. $_REQUEST['edit_id']; 100 101 $lines_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 102 103 foreach($lines_list as $row) { 104 $sql = "SELECT description FROM devices WHERE id = ".$_REQUEST['ext_list_'.$row['luid']]; 105 $name=$endpoint->db->getOne($sql); 106 107 $sql = "UPDATE endpointman_line_list SET line = '".$_REQUEST['line_list_'.$row['luid']]."', ext = ".$_REQUEST['ext_list_'.$row['luid']].", description = '".$name."' WHERE luid = ". $row['luid']; 108 $endpoint->db->query($sql); 109 } 110 111 $sql = "UPDATE endpointman_mac_list SET template_id = '".$_REQUEST['template_list']."', model = '".$_REQUEST['model_list']."' WHERE id = ". $_REQUEST['edit_id']; 150 112 $endpoint->db->query($sql); 151 113 152 $sql = 'SELECT last_insert_id()'; 153 $ext_id =& $endpoint->db->getOne($sql); 154 155 if(!isset($_REQUEST['line_list_'.$num])) { 156 $_REQUEST['line_list_'.$num] = 1; 157 } 158 159 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$ext_id."', '".$_REQUEST['ext_list_'.$num]."', '".$_REQUEST['line_list_'.$num]."', '".$name."')"; 114 $row = $endpoint->get_phone_info($_REQUEST['edit_id']); 115 $endpoint->prepare_configs($row); 116 117 $message = _("Saved")."!"; 118 break; 119 case "delete": 120 $sql = 'SELECT mac_id FROM endpointman_line_list WHERE luid = '.$_REQUEST['edit_id'] ; 121 $mac_id =& $endpoint->db->getOne($sql,array(),DB_FETCHMODE_ASSOC); 122 $row = $endpoint->get_phone_info($mac_id); 123 124 $sql = "DELETE FROM endpointman_line_list WHERE luid=".$_REQUEST['edit_id']; 160 125 $endpoint->db->query($sql); 161 162 $row_new = $endpoint->get_phone_info($ext_id); 163 $endpoint->prepare_configs($row_new); 126 $_REQUEST['edit_id'] = $mac_id; 127 $message = _("Deleted")."!"; 128 break; 129 } 130 $edit_row=$endpoint->get_phone_info($_REQUEST['edit_id']); 131 $edit_row['id'] = $_REQUEST['edit_id']; 132 $mode = "EDIT"; 133 break; 134 case "add" : 135 $mac = $endpoint->mac_check_clean($_REQUEST['mac']); 136 if($mac) { 137 $sql = 'SELECT description FROM devices WHERE id = '.$_REQUEST['ext_list']; 138 $name =& $endpoint->db->getOne($sql); 139 140 $endpoint->sync_model($_REQUEST['model_list']); 141 142 $sql = 'SELECT endpointman_product_list. * , endpointman_model_list.template_data, endpointman_brand_list.directory FROM endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_model_list.id = \''.$_REQUEST['model_list'].'\' AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id'; 143 144 $row =& $endpoint->db->getRow($sql,array(),DB_FETCHMODE_ASSOC); 145 146 $cfg_data = unserialize($row['template_data']); 147 148 $count = count($cfg_data); 149 $i = 0; 150 while($i < $count) { 151 if(array_key_exists('variable',$cfg_data[$i])) { 152 $temping = str_replace('$','',$cfg_data[$i]['variable']); 153 if(is_array($cfg_data[$i]['default_value'])) { 154 $custom_cfg_data[$temping]['value'] = ''; 155 } else { 156 $custom_cfg_data[$temping]['value'] = $cfg_data[$i]['default_value']; 157 } 158 } 159 $i++; 160 } 161 if((isset($custom_cfg_data)) AND (is_array($custom_cfg_data))) { 162 $custom_cfg_data = serialize($custom_cfg_data); 163 } else { 164 $temp = array(); 165 $custom_cfg_data = serialize($temp); 166 } 167 168 $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `global_custom_cfg_data`, `template_id`) VALUES ('".$mac."', '".$_REQUEST['model_list']."', '".$custom_cfg_data."', '".$_REQUEST['template_list']."')"; 169 $endpoint->db->query($sql); 170 171 $sql = 'SELECT last_insert_id()'; 172 $ext_id =& $endpoint->db->getOne($sql); 173 174 if(!isset($_REQUEST['line_list'])) { 175 $_REQUEST['line_list'] = 1; 176 } 177 178 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$ext_id."', '".$_REQUEST['ext_list']."', '".$_REQUEST['line_list']."', '".$name."')"; 179 $endpoint->db->query($sql); 180 181 if(!isset($_REQUEST['image_x'])) { 182 $mac_id = $endpoint->get_phone_info($ext_id); 183 184 $endpoint->prepare_configs($mac_id); 164 185 165 186 $message = _("Saved")."!"; 166 187 } else { 167 $message = _("One or more selected phones had the same extension as a phone already added, these devices were not added"); 168 } 169 170 } else { 171 $message = _("Invalid MAC Address"); 172 } 173 } 174 } elseif((isset($_REQUEST['button_update_phones'])) AND (isset($_REQUEST['selected']))) { 175 if(($_REQUEST['brand_list_selected'] > 0) AND ($_REQUEST['model_list_selected'] > 0)) { 176 foreach($_REQUEST['selected'] as $key => $data) { 177 $sql = "UPDATE endpointman_mac_list SET custom_cfg_data = '', custom_cfg_template = '', user_cfg_data = '', config_files_override = '', model = '".$_REQUEST['model_list_selected']."' WHERE id = ". $_REQUEST['selected'][$key]; 188 $_REQUEST['edit_id'] = $ext_id; 189 $edit_row=$endpoint->get_phone_info($ext_id); 190 $edit_row['id'] = $_REQUEST['edit_id']; 191 $mode = "EDIT"; 192 $_REQUEST['id'] = $_REQUEST['edit_id']; 193 if($endpoint->linesAvailable(NULL,$_REQUEST['id'])) { 194 if($endpoint->endpoint_data->all_unused_registrations()) { 195 $sql = 'SELECT * FROM `endpointman_line_list` WHERE `mac_id` = '. $_REQUEST['id']; 196 $lines_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 197 198 foreach($lines_list as $row) { 199 $sql = "SELECT description FROM devices WHERE id = ".$_REQUEST['ext_list']; 200 $name=$endpoint->db->getOne($sql); 201 202 $sql = "UPDATE endpointman_line_list SET line = '".$_REQUEST['line_list']."', ext = ".$_REQUEST['ext_list'].", description = '".$name."' WHERE luid = ". $row['luid']; 203 $endpoint->db->query($sql); 204 } 205 206 $reg = array_values($endpoint->display_registration_list()); 207 $lines = array_values($endpoint->linesAvailable(NULL,$_REQUEST['id'])); 208 209 $sql = "SELECT description FROM devices WHERE id = ".$reg[0]['value']; 210 $name=$endpoint->db->getOne($sql); 211 212 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$_REQUEST['id']."', '".$reg[0]['value']."', '".$lines[0]['value']."', '".$name."')"; 213 $endpoint->db->query($sql); 214 215 $edit_row=$endpoint->get_phone_info($ext_id); 216 $edit_row['id'] = $_REQUEST['edit_id']; 217 $message = "Configuration Files will not be Generated until you click Save!"; 218 } else { 219 $message = _("No Devices/Extensions Left to Add")."!"; 220 } 221 } else { 222 $message = _("No Lines Left to Add")."!"; 223 } 224 } 225 } else { 226 $message = _("Invalid MAC Address")."!"; 227 } 228 break; 229 case "edit_template" : 230 if(empty($_REQUEST['edit_id'])) { 231 $message = _("No Device Selected to Edit!")."!"; 232 } else { 233 $template_editor = TRUE; 234 $sql = "UPDATE endpointman_mac_list SET model = '".$_REQUEST['model_list']."' WHERE id =".$_REQUEST['edit_id']; 178 235 $endpoint->db->query($sql); 179 180 $phone_info = $endpoint->get_phone_info($_REQUEST['selected'][$key]); 181 $endpoint->prepare_configs($phone_info); 182 183 $message = _("Saved")."!"; 184 } 185 } else { 186 $message = _("Please select a Brand and/or Model"); 187 } 188 } elseif(isset($_REQUEST['button_delete_selected_phones'])) { 189 if(isset($_REQUEST['selected'])) { 190 foreach($_REQUEST['selected'] as $key => $data) { 191 $sql = "DELETE FROM endpointman_mac_list WHERE id=".$_REQUEST['selected'][$key]; 236 if ($_REQUEST['template_list'] == 0) { 237 $endpoint->edit_template_display($_REQUEST['edit_id'],1); 238 } else { 239 $endpoint->edit_template_display($_REQUEST['template_list'],0); 240 } 241 } 242 break; 243 case "delete_selected_phones": 244 if(isset($_REQUEST['selected'])) { 245 foreach($_REQUEST['selected'] as $key => $data) { 246 $sql = "DELETE FROM endpointman_mac_list WHERE id=".$_REQUEST['selected'][$key]; 247 $endpoint->db->query($sql); 248 $sql = "DELETE FROM endpointman_line_list WHERE mac_id=".$_REQUEST['selected'][$key]; 249 $endpoint->db->query($sql); 250 $message = "Deleted!"; 251 } 252 } else { 253 $message = _("No Phones Selected")."!"; 254 } 255 break; 256 case "delete_device": 257 $row = $endpoint->get_phone_info($_REQUEST['edit_id']); 258 $sql = "DELETE FROM endpointman_mac_list WHERE id=".$_REQUEST['edit_id']; 259 $endpoint->db->query($sql); 260 $sql = "DELETE FROM endpointman_line_list WHERE mac_id=".$_REQUEST['edit_id']; 261 $endpoint->db->query($sql); 262 $message = _("Deleted")."!"; 263 break; 264 case "delete_line" : 265 $sql = 'SELECT mac_id FROM endpointman_line_list WHERE luid = '.$_REQUEST['edit_id'] ; 266 $mac_id =& $endpoint->db->getOne($sql,array(),DB_FETCHMODE_ASSOC); 267 $row = $endpoint->get_phone_info($mac_id); 268 269 $sql = 'SELECT COUNT(*) FROM endpointman_line_list WHERE mac_id = 31'; 270 $num_lines =& $endpoint->db->getOne($sql,array(),DB_FETCHMODE_ASSOC); 271 if($num_lines > 1) { 272 $sql = "DELETE FROM endpointman_line_list WHERE luid=".$_REQUEST['edit_id']; 192 273 $endpoint->db->query($sql); 193 $sql = "DELETE FROM endpointman_line_list WHERE mac_id=".$_REQUEST['selected'][$key]; 194 $endpoint->db->query($sql); 195 } 196 } else { 197 $message = _("No Phones Selected")."!"; 198 } 199 } elseif(isset($_REQUEST['button_go'])) { 200 if ($_REQUEST['nmap'] == 1) { 201 $temp = $endpoint->discover_new($_REQUEST['netmask']); 202 } else { 203 $temp = $endpoint->discover_new($_REQUEST['netmask'], FALSE); 204 } 205 $count = count($temp); 206 $i = 0; 207 while($i < $count) { 208 if (!$temp[$i]['endpoint_managed']) { 209 if ($temp[$i]['brand']) { 210 $final[$i] = $temp[$i]; 211 $final[$i]['id'] = $i; 212 $sqln = "SELECT * FROM endpointman_model_list WHERE enabled = 1 AND brand =".$temp[$i]['brand_id']; 274 $message = _("Deleted")."!"; 275 } else { 276 $message = _("You can't remove the only line left")."!"; 277 } 278 break; 279 case "rebuild_selected_phones": 280 if(isset($_REQUEST['selected'])) { 281 foreach($_REQUEST['selected'] as $key => $data) { 282 $phone_info = $endpoint->get_phone_info($_REQUEST['selected'][$key]); 283 if(isset($_REQUEST['reboot'])) { 284 $endpoint->prepare_configs($phone_info); 285 } else { 286 $endpoint->prepare_configs($phone_info,FALSE); 287 } 288 } 289 $message = "Rebuilt Configs & Rebooted Selected Phones"; 290 } else { 291 $message = _("No Phones Selected")."!"; 292 } 293 break; 294 case "rebuild_configs_for_all_phones" : 295 $sql = "SELECT endpointman_mac_list.id FROM endpointman_mac_list, endpointman_brand_list, endpointman_product_list, endpointman_model_list WHERE endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.model = endpointman_model_list.id ORDER BY endpointman_product_list.cfg_dir ASC"; 296 $mac_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 297 foreach($mac_list as $data) { 298 $phone_info = $endpoint->get_phone_info($data['id']); 299 foreach($phone_info['line'] as $line) { 300 $sql = "UPDATE endpointman_line_list SET description = '".$line['description']."' WHERE luid = ".$line['luid']; 301 $endpoint->db->query($sql); 302 } 303 if(isset($_REQUEST['reboot'])) { 304 $endpoint->prepare_configs($phone_info); 305 } else { 306 $endpoint->prepare_configs($phone_info,FALSE); 307 } 308 } 309 $message = "Rebuilt Configs & Rebooted All Phones"; 310 break; 311 case "reboot_brand" : 312 if($_REQUEST['rb_brand'] != "") { 313 $sql = 'SELECT endpointman_mac_list.id FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list , endpointman_product_list WHERE endpointman_brand_list.id = endpointman_model_list.brand AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_brand_list.id = '.$_REQUEST['rb_brand'].' ORDER BY endpointman_product_list.cfg_dir ASC'; 314 $data =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 315 if(!empty($data)) { 316 foreach($data as $row) { 317 if(!class_exists('ProvisionerConfig')) { 318 require(PHONE_MODULES_PATH.'setup.php'); 319 } 320 $phone_info = $endpoint->get_phone_info($row['id']); 321 322 $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; 323 324 $provisioner_lib = new $class(); 325 326 $provisioner_lib->root_dir = PHONE_MODULES_PATH; 327 328 $provisioner_lib->engine = 'asterisk'; 329 $provisioner_lib->system = 'unix'; 330 331 //have to because of versions less than php5.3 332 $provisioner_lib->brand_name = $phone_info['directory']; 333 $provisioner_lib->family_line = $phone_info['cfg_dir']; 334 335 $provisioner_lib->lines[1] = array('ext' => $phone_info['line'][1]['ext']); 336 $provisioner_lib->reboot(); 337 unset($provisioner_lib); 338 } 339 $message = "Rebooted all ". $phone_info['name'] . " phones"; 340 } else { 341 $message = _("No Phones to Reboot"); 342 } 343 } else { 344 $message = _("No Brand Selected for Reboot"); 345 } 346 break; 347 case "go" : 348 if ((isset($_REQUEST['nmap'])) AND ($_REQUEST['nmap'] == 1)) { 349 $temp = $endpoint->discover_new($_REQUEST['netmask']); 350 } else { 351 $temp = $endpoint->discover_new($_REQUEST['netmask'], FALSE); 352 } 353 354 foreach($temp as $key => $data) { 355 if ((!$data['endpoint_managed']) AND ($data['brand'])) { 356 $final[$key] = $data; 357 $final[$key]['id'] = $key; 358 $sqln = "SELECT * FROM endpointman_model_list WHERE enabled = 1 AND brand =".$data['brand_id']; 213 359 $model_list =& $endpoint->db->getAll($sqln,array(),DB_FETCHMODE_ASSOC); 214 360 $j = 0; 215 361 foreach($model_list as $row) { 216 $final[$ i]['list'][$j] = $row;362 $final[$key]['list'][$j] = $row; 217 363 $j++; 218 364 } 219 365 } 220 366 } 221 $i++; 222 } 223 if($final) { 224 $final = array_values($final); 225 } else { 226 $final = NULL; 227 $message = _("No Devices Found"); 228 } 229 $searched = 1; 230 } elseif(isset($_REQUEST['button_rebuild_configs_for_all_phones'])) { 231 $sql = "SELECT endpointman_mac_list.id FROM endpointman_mac_list, endpointman_brand_list, endpointman_product_list, endpointman_model_list WHERE endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.model = endpointman_model_list.id ORDER BY endpointman_product_list.cfg_dir ASC"; 232 $mac_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 233 foreach($mac_list as $data) { 234 $phone_info = $endpoint->get_phone_info($data['id']); 235 $endpoint->prepare_configs($phone_info); 236 foreach($phone_info['line'] as $line) { 237 $sql = "UPDATE endpointman_line_list SET description = '".$line['description']."' WHERE luid = ".$line['luid']; 238 $endpoint->db->query($sql); 239 } 240 } 241 } elseif(isset($_REQUEST['button_rebuild_reboot'])) { 242 if($_REQUEST['product_select'] == "") { 243 $message = _("Please select a product"); 244 } elseif($_REQUEST['template_selector'] == "") { 245 $message = _("Please select a template"); 246 } else { 247 $sql = "SELECT endpointman_mac_list.id FROM endpointman_mac_list, endpointman_brand_list, endpointman_product_list, endpointman_model_list WHERE endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_product_list.id = '".$_REQUEST['product_select']."'"; 248 $data =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 249 foreach($data as $row) { 250 $sql = "UPDATE endpointman_mac_list SET custom_cfg_template = '".$_REQUEST['template_selector']."' WHERE id = ". $row['id']; 251 $endpoint->db->query($sql); 252 $phone_info = $endpoint->get_phone_info($row['id']); 253 $endpoint->prepare_configs($phone_info); 254 foreach($phone_info['line'] as $line) { 255 $sql = "UPDATE endpointman_line_list SET description = '".$line['description']."' WHERE luid = ".$line['luid']; 367 368 if($final) { 369 //$final = array_values($final); 370 } else { 371 $final = NULL; 372 $message = _("No Devices Found"); 373 } 374 $searched = 1; 375 break; 376 case "add_selected_phones" : 377 if(isset($_REQUEST['add'])) { 378 foreach($_REQUEST['add'] as $num) { 379 if($mac = $endpoint->mac_check_clean($_REQUEST['mac_'.$num])) { 380 $sql = "SELECT * FROM endpointman_line_list WHERE ext = ".$_REQUEST['ext_list_'.$num]; 381 $res =& $endpoint->db->query($sql); 382 $count_macs = $res->numRows(); 383 if(!$count_macs) { 384 $sql = 'SELECT `name` FROM `users` WHERE `extension` = '.$_REQUEST['ext_list_'.$num]; 385 $name =& $endpoint->db->getOne($sql,array(),DB_FETCHMODE_ASSOC); 386 387 388 //$sql = 'SELECT endpointman_product_list. * , endpointman_brand_list.directory FROM endpointman_model_list, endpointman_brand_list, endpointman_product_list WHERE endpointman_model_list.id = \''.$_REQUEST['model_list_'.$num].'\' AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id'; 389 //$row =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 390 391 392 $sql = "INSERT INTO `endpointman_mac_list` (`mac`, `model`, `template_id`) VALUES ('".$mac."', '".$_REQUEST['model_list_'.$num]."', '0')"; 393 $endpoint->db->query($sql); 394 395 $sql = 'SELECT last_insert_id()'; 396 $ext_id =& $endpoint->db->getOne($sql); 397 398 if(!isset($_REQUEST['line_list_'.$num])) { 399 $_REQUEST['line_list_'.$num] = 1; 400 } 401 402 $sql = "INSERT INTO `endpointman_line_list` (`mac_id`, `ext`, `line`, `description`) VALUES ('".$ext_id."', '".$_REQUEST['ext_list_'.$num]."', '".$_REQUEST['line_list_'.$num]."', '".$name."')"; 403 $endpoint->db->query($sql); 404 405 $row_new = $endpoint->get_phone_info($ext_id); 406 $rebooted = ""; 407 if(isset($_REQUEST['reboot_sel'])) { 408 $endpoint->prepare_configs($row_new); 409 $rebooted = " & Rebooted"; 410 } else { 411 $endpoint->prepare_configs($row_new,FALSE); 412 } 413 $message = _("Saved").$rebooted."!"; 414 } else { 415 $message = _("One or more selected phones had the same extension as a phone already added, these devices were not added"); 416 } 417 418 } else { 419 $message = _("Invalid MAC Address"); 420 } 421 } 422 } 423 break; 424 case "change_brand" : 425 if(isset($_REQUEST['selected'])) { 426 if(($_REQUEST['brand_list_selected'] > 0) AND ($_REQUEST['model_list_selected'] > 0)) { 427 foreach($_REQUEST['selected'] as $key => $data) { 428 $sql = "UPDATE endpointman_mac_list SET global_custom_cfg_data = '', template_id = 0, global_user_cfg_data = '', config_files_override = '', model = '".$_REQUEST['model_list_selected']."' WHERE id = ". $_REQUEST['selected'][$key]; 429 $endpoint->db->query($sql); 430 431 $phone_info = $endpoint->get_phone_info($_REQUEST['selected'][$key]); 432 $endpoint->prepare_configs($phone_info); 433 $rebooted = ""; 434 if(isset($_REQUEST['reboot_change'])) { 435 $endpoint->prepare_configs($phone_info); 436 $rebooted = " & Rebooted"; 437 } else { 438 $endpoint->prepare_configs($phone_info,FALSE); 439 } 440 $message = _("Saved").$rebooted."!"; 441 } 442 } else { 443 $message = _("Please select a Brand and/or Model"); 444 } 445 } else { 446 $message = _("No Phones Selected!"); 447 } 448 break; 449 case "rebuild_reboot" : 450 if($_REQUEST['product_select'] == "") { 451 $message = _("Please select a product"); 452 } elseif($_REQUEST['template_selector'] == "") { 453 $message = _("Please select a template"); 454 } else { 455 $sql = "SELECT endpointman_mac_list.id FROM endpointman_mac_list, endpointman_brand_list, endpointman_product_list, endpointman_model_list WHERE endpointman_brand_list.id = endpointman_product_list.brand AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_product_list.id = '".$_REQUEST['product_select']."'"; 456 $data =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 457 foreach($data as $row) { 458 $sql = "UPDATE endpointman_mac_list SET template_id = '".$_REQUEST['template_selector']."' WHERE id = ". $row['id']; 256 459 $endpoint->db->query($sql); 257 } 258 } 259 } 260 } elseif(isset($_REQUEST['button_rebuild_selected'])) { 261 if(isset($_REQUEST['selected'])) { 262 foreach($_REQUEST['selected'] as $key => $data) { 263 $phone_info = $endpoint->get_phone_info($_REQUEST['selected'][$key]); 264 $endpoint->prepare_configs($phone_info); 265 } 266 } else { 267 $message = _("No Phones Selected")."!"; 268 } 269 } elseif(isset($_REQUEST['button_reboot_this_brand'])) { 270 if($_REQUEST['rb_brand'] != "") { 271 $sql = 'SELECT endpointman_mac_list.id FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list , endpointman_product_list WHERE endpointman_brand_list.id = endpointman_model_list.brand AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_brand_list.id = '.$_REQUEST['rb_brand'].' ORDER BY endpointman_product_list.cfg_dir ASC'; 272 $data =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 273 foreach($data as $row) { 274 if(!class_exists('ProvisionerConfig')) { 275 require(PHONE_MODULES_PATH.'setup.php'); 276 } 277 $phone_info = $endpoint->get_phone_info($row['id']); 278 if(is_array($phone_info['template_data'])) { 279 $template_data = unserialize($phone_info['template_data']['custom_cfg_data']); 280 } else { 281 $template_data = unserialize($phone_info['custom_cfg_data']); 282 } 283 284 $new_template_data = array(); 285 if(is_array($template_data)) { 286 foreach($template_data as $key => $data) { 287 $new_template_data = array_merge($new_template_data, array($key => $data['value'])); 288 } 289 } 290 291 $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; 292 293 $provisioner_lib = new $class(); 294 295 $provisioner_lib->root_dir = PHONE_MODULES_PATH; 296 297 $provisioner_lib->engine = 'asterisk'; 298 $provisioner_lib->system = 'unix'; 299 300 $provisioner_lib->options = $new_template_data; 301 302 //have to because of versions less than php5.3 303 $provisioner_lib->brand_name = $phone_info['directory']; 304 $provisioner_lib->family_line = $phone_info['cfg_dir']; 305 306 $provisioner_lib->lines[1] = array('ext' => $phone_info['ext']); 307 $provisioner_lib->reboot(); 308 unset($provisioner_lib); 309 } 310 } else { 311 $message = _("No Brand Selected for Reboot"); 312 } 460 $phone_info = $endpoint->get_phone_info($row['id']); 461 if(isset($_REQUEST['reboot'])) { 462 $endpoint->prepare_configs($phone_info); 463 } else { 464 $endpoint->prepare_configs($phone_info,FALSE); 465 } 466 foreach($phone_info['line'] as $line) { 467 $sql = "UPDATE endpointman_line_list SET description = '".$line['description']."' WHERE luid = ".$line['luid']; 468 $endpoint->db->query($sql); 469 } 470 } 471 $message = "Rebuilt Configs"; 472 } 473 break; 313 474 } 314 475 315 $sql = 'SELECT endpointman_mac_list.id , endpointman_mac_list.mac , endpointman_model_list.model, endpointman_model_list.enabled , endpointman_brand_list.name, endpointman_mac_list.global_custom_cfg_data, endpointman_mac_list.template_id FROM endpointman_mac_list , endpointman_model_list , endpointman_brand_list WHERE ( endpointman_model_list.id = endpointman_mac_list.model ) AND ( endpointman_model_list.brand = endpointman_brand_list.id )'; 316 317 $devices_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 318 476 //Refresh the list after processing 477 $devices_list =& $endpoint->endpoint_data->all_devices();; 319 478 320 479 $i = 0; 321 480 $list = array(); 322 481 foreach($devices_list as $devices_row) { 323 $sql = 'SELECT * FROM endpointman_line_list WHERE mac_id = '.$devices_row['id']; 324 $line_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 482 $line_list =& $endpoint->endpoint_data->get_lines_from_device($devices_row['id']); 325 483 $list[$i] = $devices_row; 326 484 $z = 0; 485 if (($devices_row['template_id'] == 0) && (isset($devices_row['global_custom_cfg_data'])) ) { 486 $list[$i]['template_name'] = "Custom-".$devices_row['mac']; 487 } elseif((!isset($devices_row['custom_cfg_data'])) && ($devices_row['template_id'] == 0)) { 488 $list[$i]['template_name'] = "N/A"; 489 } else { 490 $sql = "SELECT name FROM endpointman_template_list WHERE id =".$devices_row['template_id']; 491 $template_name =& $endpoint->db->getOne($sql); 492 $list[$i]['template_name'] = $template_name; 493 } 494 if (!$devices_row['enabled']) { 495 $list[$i]['model'] = $devices_row['model']."<i>(Disabled)</i>"; 496 } 497 $list[$i]['master_id'] = $i; 327 498 foreach($line_list as $line_row) { 328 $list[$i]['ext'] = $line_row['ext']; 329 $list[$i]['line'] = $line_row['line']; 330 $list[$i]['description'] = $line_row['description']; 331 if (($devices_row['template_id'] == 0) && (isset($devices_row['global_custom_cfg_data'])) ) { 332 $list[$i]['template_name'] = "Custom-".$devices_row['mac']; 333 } elseif((!isset($devices_row['custom_cfg_data'])) && ($devices_row['template_id'] == 0)) { 334 $list[$i]['template_name'] = "N/A"; 335 } else { 336 $sql = "SELECT name FROM endpointman_template_list WHERE id =".$devices_row['template_id']; 337 $template_name =& $endpoint->db->getOne($sql); 338 $list[$i]['template_name'] = $template_name; 339 } 340 if (!$devices_row['enabled']) { 341 $list[$i]['model'] = $devices_row['model']."<i>(Disabled)</i>"; 342 } 499 $list[$i]['line'][$z]['ext'] = $line_row['ext']; 500 $list[$i]['line'][$z]['line'] = $line_row['line']; 501 $list[$i]['line'][$z]['description'] = $line_row['description']; 502 $list[$i]['line'][$z]['luid'] = $line_row['luid']; 503 $list[$i]['line'][$z]['master_id'] = $i; 343 504 $z++; 344 505 } … … 346 507 } 347 508 348 349 $sql = 'SELECT * FROM endpointman_mac_list WHERE model = 0'; 350 351 $unknown_list =& $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); 509 $unknown_list =& $endpoint->endpoint_data->all_unknown_devices(); 352 510 353 511 foreach($unknown_list as $row) { #Displays unknown phones in the database with edit and delete buttons … … 383 541 384 542 } else { 385 $ tpl = new RainTPL( LOCAL_PATH.'templates');386 $ tpl->assign("list", $list);387 $ tpl->assign("error", "");388 $ tpl->assign("srvip", $_SERVER["SERVER_ADDR"]);389 $ tpl->assign("web_var", "?type=$type");390 if($ma = $endpoint->modelsAvailable()) {391 $ tpl->assign("models_ava", $ma);392 } 393 $ tpl->assign("web_path", WEB_PATH);394 $ tpl->assign("product_list", $product_list);395 $ tpl->assign("display_ext", $endpoint->displayExtension());396 $ tpl->assign("brand_ava", $endpoint->brandAvailable());397 $ tpl->assign("unmanaged", $final);398 $ tpl->assign("button", $button);399 $ tpl->assign("searched", $searched);400 $ tpl->assign("edit", $edit);401 $ tpl->assign("amp_conf_serial", base64_encode(serialize($amp_send)));402 $ tpl->assign("no_add", $no_add);403 $ tpl->assign("mode", $mode);543 $endpoint->tpl->assign("list", $list); 544 $endpoint->tpl->assign("error", ""); 545 $endpoint->tpl->assign("srvip", $_SERVER["SERVER_ADDR"]); 546 $endpoint->tpl->assign("web_var", "?type=$type"); 547 $ma = $endpoint->models_available(); 548 if($ma != FALSE) { 549 $endpoint->tpl->assign("models_ava", $ma); 550 } 551 $endpoint->tpl->assign("web_path", WEB_PATH); 552 $endpoint->tpl->assign("product_list", $product_list); 553 $endpoint->tpl->assign("display_ext", $endpoint->display_registration_list()); 554 $endpoint->tpl->assign("brand_ava", $endpoint->brands_available()); 555 $endpoint->tpl->assign("unmanaged", $final); 556 $endpoint->tpl->assign("button", $button); 557 $endpoint->tpl->assign("searched", $searched); 558 $endpoint->tpl->assign("edit", $edit); 559 $endpoint->tpl->assign("amp_conf_serial", base64_encode(serialize($amp_send))); 560 $endpoint->tpl->assign("no_add", $no_add); 561 $endpoint->tpl->assign("mode", $mode); 404 562 405 563 if(isset($final)) { 406 $ tpl->assign("cached_devices", base64_encode(serialize($final)));564 $_SESSION['dev_cache'] = base64_encode(serialize($final)); 407 565 } 408 566 409 567 if (isset($mode) && ($mode == "EDIT")) { 410 if($ma = $endpoint->modelsAvailable($edit_row['model_id'],NULL,$edit_row['brand_id'])) { 411 $tpl->assign("mac", $edit_row['mac']); 412 $tpl->assign("name", $edit_row['name']); 413 $tpl->assign("brand_id", $edit_row['brand_id']); 414 $tpl->assign("models_ava", $ma); 415 $tpl->assign("display_ext", $endpoint->displayExtension($edit_row['line'][1]['luid'])); 416 $tpl->assign("display_templates", $endpoint->display_templates($edit_row['product_id'],$edit_row['template_id'])); 417 $tpl->assign("edit_id", $edit_row['id']); 568 $ma = $endpoint->models_available($edit_row['model_id'],$edit_row['brand_id']); 569 if($ma != FALSE) { 570 $endpoint->tpl->assign("mac", $edit_row['mac']); 571 $endpoint->tpl->assign("name", $edit_row['name']); 572 $b=0; 573 foreach($edit_row['line'] as $data) { 574 $edit_row['line'][$data['line']]['reg_list'] = $endpoint->display_registration_list($data['luid']); 575 $edit_row['line'][$data['line']]['line_list'] = $endpoint->linesAvailable($data['luid']); 576 $b++; 577 } 578 if($b == 1) { 579 $endpoint->tpl->assign("disabled_delete_line", 1); 580 } 581 $endpoint->tpl->assign("line_list_edit", $edit_row['line']); 582 583 $endpoint->tpl->assign("brand_id", $edit_row['brand_id']); 584 $endpoint->tpl->assign("models_ava", $ma); 585 //$endpoint->tpl->assign("display_ext", $endpoint->display_registration_list($edit_row['line'][2]['luid'])); 586 //$endpoint->tpl->assign("display_ext", $edit_row['line']); 587 588 $endpoint->tpl->assign("display_templates", $endpoint->display_templates($edit_row['product_id'],$edit_row['template_id'])); 589 $endpoint->tpl->assign("edit_id", $edit_row['id']); 418 590 } else { 419 591 $message = _("You have disabled/removed all models that correspond to this brand. Please enable them in 'Brand Configurations/Setup' before trying to edit this phone"); 420 $ tpl->assign("mode", NULL);592 $endpoint->tpl->assign("mode", NULL); 421 593 } 422 594 } … … 431 603 432 604 if(isset($message)) { 433 $endpoint->display_message_box($message,$ tpl,0);605 $endpoint->display_message_box($message,$endpoint->tpl,0); 434 606 } 435 607 436 608 if(isset($error_message)) { 437 $endpoint->display_message_box($error_message,$ tpl,1);609 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 438 610 } 439 611 440 612 //draw the template 441 echo $ tpl->draw( 'devices_manager' );613 echo $endpoint->tpl->draw( 'devices_manager' ); 442 614 } modules/branches/2.9/endpointman/includes/export.php
r10240 r10792 18 18 $outstream = fopen("php://output",'w'); 19 19 20 $sql = 'SELECT endpointman_mac_list.mac, endpointman_brand_list.name, endpointman_model_list.model, endpointman_line_list.ext FROM endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_line_list WHERE endpointman_line_list.mac_id = endpointman_mac_list.id AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_model_list.brand = endpointman_brand_list.id';20 $sql = 'SELECT endpointman_mac_list.mac, endpointman_brand_list.name, endpointman_model_list.model, endpointman_line_list.ext,endpointman_line_list.line FROM endpointman_mac_list, endpointman_model_list, endpointman_brand_list, endpointman_line_list WHERE endpointman_line_list.mac_id = endpointman_mac_list.id AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_model_list.brand = endpointman_brand_list.id'; 21 21 22 22 $result = $endpoint->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); modules/branches/2.9/endpointman/includes/functions.inc
r10322 r10792 14 14 public $global_cfg; 15 15 public $error; 16 public $endpoint_data; 17 public $tpl; 16 18 17 19 /** … … 21 23 */ 22 24 function __construct() { 23 global $amp_conf, $db, $global_cfg; 25 require('abstraction/freepbx.inc'); 26 $this->endpoint_data = new epm_data_abstraction(); 27 28 $this->global_cfg = $this->endpoint_data->get_stored_globals(); 29 30 $this->db = $this->endpoint_data->db; 24 31 25 32 //TODO: Need to have this change when the user changes timezones, for now we keep it set to my timezone 26 33 date_default_timezone_set('America/Los_Angeles'); 27 34 28 //The only time dbh_asterisk is set is when we are inside the ARI Recording interface 29 if(isset($_SESSION['dbh_asterisk'])) { 30 $this->db = $_SESSION['dbh_asterisk']; 31 //We don't want to reference the recordings directory when in the recording interface. 32 $_SERVER["SCRIPT_FILENAME"] = str_replace("recordings/", "admin/", $_SERVER["SCRIPT_FILENAME"]); 33 } else { 34 $this->db = $db; 35 } 36 37 //Move all information from the global $amp_conf into our public space. This will help prevent security concerns 35 //Move all information from the global $amp_conf into our public space. This will help prevent security concerns 38 36 $this->amp_conf = $amp_conf; 39 37 40 38 //Generate empty array 41 39 $this->error = array(); 42 43 //Get all global variables44 $this->global_cfg =& $this->db->getAssoc("SELECT var_name, value FROM endpointman_global_vars");45 40 46 41 //TODO: Possibly remove these as I don't believe anything uses them anymore … … 55 50 define("WEB_PATH", dirname($_SERVER['SCRIPT_NAME'])."/modules/endpointman/"); 56 51 define("LOCAL_PATH", dirname($_SERVER["SCRIPT_FILENAME"])."/modules/endpointman/"); 57 52 58 53 //Define error reporting 59 54 if($this->global_cfg['debug']) { … … 79 74 80 75 //include the local template class 81 include LOCAL_PATH."includes/rain.tpl.class.php"; 76 require(LOCAL_PATH."includes/rain.tpl.class.php"); 77 78 $this->tpl = new RainTPL( LOCAL_PATH.'templates/freepbx', LOCAL_PATH.'templates/freepbx/compiled', '/admin/modules/endpointman/templates/images' ); 79 82 80 } 83 81 … … 265 263 $sql = "SELECT name, global_custom_cfg_data, config_files_override FROM endpointman_template_list WHERE id = ".$phone_info['template_id']; 266 264 267 $phone_info['template_data '] =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC);268 269 } 270 271 $sql = "SELECT endpointman_line_list.*, sip.data as secret, devices.* FROM endpointman_line_list, sip, devices WHERE endpointman_line_list.ext = devices.id AND endpointman_line_list.ext = sip.id AND sip.keyword = 'secret' AND mac_id = ".$mac_id ;265 $phone_info['template_data_info'] =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 266 267 } 268 269 $sql = "SELECT endpointman_line_list.*, sip.data as secret, devices.* FROM endpointman_line_list, sip, devices WHERE endpointman_line_list.ext = devices.id AND endpointman_line_list.ext = sip.id AND sip.keyword = 'secret' AND mac_id = ".$mac_id." ORDER BY endpointman_line_list.line ASC"; 272 270 $lines_info =& $this->db->getAll($sql, array(), DB_FETCHMODE_ASSOC); 273 271 foreach($lines_info as $line) { … … 355 353 */ 356 354 function edit_template_display($id, $custom) { 355 //endpointman_flush_buffers(); 356 357 357 358 $alt_configs = NULL; 358 359 … … 373 374 //Determine if we are dealing with a general template or a specific [for that phone only] template (custom =0 means general) 374 375 if($custom == 0) { 375 $sql = "SELECT endpointman_model_list.m odel as model_name, endpointman_template_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_product_list.short_name, endpointman_product_list.id as product_id, endpointman_model_list.template_data, endpointman_model_list.id as model_id, endpointman_template_list.* FROM endpointman_product_list, endpointman_model_list, endpointman_template_list WHERE endpointman_product_list.id = endpointman_template_list.product_id AND endpointman_template_list.model_id = endpointman_model_list.id AND endpointman_template_list.id = ".$id;376 } else { 377 $sql = "SELECT endpointman_model_list.m odel as model_name, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_line_list.*, endpointman_model_list.id as model_id, endpointman_model_list.template_data, endpointman_product_list.id as product_id, endpointman_product_list.short_name, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_brand_list, endpointman_mac_list, endpointman_model_list, endpointman_product_list, endpointman_line_list WHERE endpointman_mac_list.id=".$id." AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id";376 $sql = "SELECT endpointman_model_list.max_lines, endpointman_model_list.model as model_name, endpointman_template_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_product_list.short_name, endpointman_product_list.id as product_id, endpointman_model_list.template_data, endpointman_model_list.id as model_id, endpointman_template_list.* FROM endpointman_product_list, endpointman_model_list, endpointman_template_list WHERE endpointman_product_list.id = endpointman_template_list.product_id AND endpointman_template_list.model_id = endpointman_model_list.id AND endpointman_template_list.id = ".$id; 377 } else { 378 $sql = "SELECT endpointman_model_list.max_lines, endpointman_model_list.model as model_name, endpointman_mac_list.global_custom_cfg_data, endpointman_product_list.config_files, endpointman_mac_list.*, endpointman_line_list.*, endpointman_model_list.id as model_id, endpointman_model_list.template_data, endpointman_product_list.id as product_id, endpointman_product_list.short_name, endpointman_product_list.cfg_dir, endpointman_brand_list.directory FROM endpointman_brand_list, endpointman_mac_list, endpointman_model_list, endpointman_product_list, endpointman_line_list WHERE endpointman_mac_list.id=".$id." AND endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_mac_list.model = endpointman_model_list.id AND endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.product_id = endpointman_product_list.id"; 378 379 } 379 380 380 381 $row =& $this->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 381 382 382 $tpl = new RainTPL( LOCAL_PATH.'templates' ); 383 $tpl->assign("template_editor_display", 1); 384 385 echo $tpl->draw( 'global_header' ); 383 $this->tpl->assign("template_editor_display", 1); 384 echo $this->tpl->draw( 'global_header' ); 386 385 //Let the template system know if we are working with a general template or a specific [for that phone only] template 387 $t pl->assign("custom", $custom);386 $this->tpl->assign("custom", $custom); 388 387 if($custom) { 389 $tpl->assign("ext", $row['ext']); 390 } else { 391 $tpl->assign("template_name", $row['name']); 392 } 393 $tpl->assign("product", $row['short_name']); 394 $tpl->assign("model", $row['model_name']); 395 396 if($ma = $this->modelsAvailable($row['model_id'], NULL, NULL, $row['product_id'])) { 397 $tpl->assign("models_ava", $ma); 398 } 399 400 $tpl->assign("area_ava", $this->areaAvailable($row['model_id'])); 388 $this->tpl->assign("ext", $row['ext']); 389 } else { 390 $this->tpl->assign("template_name", $row['name']); 391 } 392 $this->tpl->assign("product", $row['short_name']); 393 $this->tpl->assign("model", $row['model_name']); 394 395 if($ma = $this->models_available($row['model_id'], NULL, $row['product_id'])) { 396 $this->tpl->assign("models_ava", $ma); 397 } 398 399 if(isset($_REQUEST['maxlines'])) { 400 $areas = $this->areaAvailable($row['model_id'],$_REQUEST['maxlines']); 401 } else { 402 $areas = $this->areaAvailable($row['model_id'], 3); 403 } 404 405 $this->tpl->assign("area_ava", $areas); 401 406 //Start the display of the html file in the product folder 402 407 if($row['config_files_override'] == "") { … … 408 413 $i = 0; 409 414 $alt = 0; 410 //TODO: Perhaps fix this alternative files list 415 416 $i=0; 417 $b=0; 418 $only_configs = array(); 411 419 foreach($config_files_list as $files) { 412 420 $sql = "SELECT * FROM endpointman_custom_configs WHERE product_id = '".$row['product_id']."' AND original_name = '".$files."'"; … … 414 422 if($alt_configs_list_count->numRows() > 0) { 415 423 $alt_configs_list =& $this->db->getAll($sql, array(), DB_FETCHMODE_ASSOC); 416 $alt_configs .= $files; 417 $alt_configs .= '<select name="'.$files.'">'; 418 $alt_configs .= '<option value="0">'.$files.' (Original)</option>'; 424 $alt_configs[$i]['name'] = $files; 419 425 $files = str_replace(".","_",$files); 426 $h=0; 420 427 foreach($alt_configs_list as $ccf) { 421 $alt_configs .= '<option value="'.$ccf['id'].'" ';428 $alt_configs[$i]['list'][$h]['id'] = $ccf['id']; 422 429 $cf_key = $files; 423 if((is _array($config_files_saved)) AND ($config_files_saved[$cf_key] == $ccf['id'])) {424 $alt_configs .= 'selected';425 } 426 $alt_configs .= '>'.$ccf['name'].'</option>';427 }428 $alt_configs .= "</select>";430 if((isset($config_files_saved[$cf_key])) AND (is_array($config_files_saved)) AND ($config_files_saved[$cf_key] == $ccf['id'])) { 431 $alt_configs[$i]['list'][$h]['selected'] = 'selected'; 432 } 433 $alt_configs[$i]['list'][$h]['name'] = $ccf['name']; 434 $h++; 435 } 429 436 $alt = 1; 437 } else { 438 $only_configs[$b]['name'] = $files; 439 $b++; 430 440 } 431 441 $i++; 432 442 } 433 443 434 $tpl->assign("alt_configs", $alt_configs); 435 $tpl->assign("alt", $alt); 436 444 $this->tpl->assign("only_configs", $only_configs); 445 $this->tpl->assign("alt_configs", $alt_configs); 446 $this->tpl->assign("alt", $alt); 447 if(!isset($_REQUEST['maxlines'])) { 448 $maxlines = $row['max_lines']; 449 } else { 450 $maxlines = $_REQUEST['maxlines']; 451 } 437 452 if($row['template_data'] != "") { 438 $out = $this->generate_gui_html($row['template_data'],$row['global_custom_cfg_data'],TRUE );453 $out = $this->generate_gui_html($row['template_data'],$row['global_custom_cfg_data'],TRUE, NULL, $maxlines); 439 454 } else { 440 455 echo "No Template Data has been defined for this Product<br />"; 441 456 } 442 443 $tpl->assign("template_editor", $out); 444 $tpl->assign("hidden_id", $row['id']); 445 $tpl->assign("hidden_custom", $custom); 446 echo $tpl->draw( 'template_editor' ); 447 448 $tpl->assign("debug", ""); 457 $this->tpl->assign("web_path", WEB_PATH); 458 459 $this->tpl->assign("template_editor", $out); 460 $this->tpl->assign("hidden_id", $row['id']); 461 $this->tpl->assign("hidden_custom", $custom); 462 echo $this->tpl->draw( 'template_editor' ); 463 464 $this->tpl->assign("debug", ""); 449 465 450 466 } … … 458 474 * @return <type> 459 475 */ 460 function generate_gui_html($cfg_data,$custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL ) {476 function generate_gui_html($cfg_data,$custom_cfg_data=NULL, $admin=FALSE, $user_cfg_data=NULL,$max_lines=3,$ext=NULL) { 461 477 //take the data out of the database and turn it back into an array for use 462 478 $cfg_data = unserialize($cfg_data); … … 465 481 466 482 //Check to see if there is a custom template for this phone already listed in the endpointman_mac_list database 467 if ( isset($custom_cfg_data)) {483 if (!empty($custom_cfg_data)) { 468 484 $custom_cfg_data = unserialize($custom_cfg_data); 469 } else { 470 //No custom template so let's pull the default values for this model into the custom_cfg_data array and populate it from there so that we won't have to make two completely different functions below 471 foreach($cfg_data as $key => $data) { 472 if(($data['type'] != 'group') && ($data['type'] != 'break') && ($data['type'] != 'loop')) { 473 $key_default = str_replace('$','',$data['variable']); 474 if(!is_array($data['default_value'])) { 475 $custom_cfg_data[$key_default]['value'] = $data['default_value']; 476 } else { 477 $custom_cfg_data[$key_default]['value'] = ""; 478 } 479 } 480 } 485 if(array_key_exists('data', $custom_cfg_data)) { 486 $custom_cfg_data_ari = $custom_cfg_data['ari']; 487 $custom_cfg_data = $custom_cfg_data['data']; 488 } else { 489 $custom_cfg_data_ari = array(); 490 } 491 } else { 492 $custom_cfg_data = array(); 493 $custom_cfg_data_ari = array(); 481 494 } 482 495 if(isset($user_cfg_data)) { … … 485 498 486 499 $template_variables_array = array(); 487 488 500 $group_count = 0; 489 //Fill the html form data with values from either the database or the default values to display to the end user 490 for($i=0;$i<$count;$i++) { 491 if(array_key_exists('variable',$cfg_data[$i])) { 492 $key = str_replace('$','',$cfg_data[$i]['variable']); 493 } else { 494 $key = ""; 495 } 496 if(($admin) OR (isset($custom_cfg_data[$key]['ari']))) { 497 //Checks to see if values are defined in the database, if not then we assume this is a new option and we need a default value here! 498 if(!isset($custom_cfg_data[$key]['value'])) { 499 //xml2array will take values that have no data and turn them into arrays, we want to avoid the word 'array' as a default value, so we blank it out here if we are an array 500 if((array_key_exists('default_value',$cfg_data[$i])) AND (is_array($cfg_data[$i]['default_value']))) { 501 $custom_cfg_data[$key]['value'] = ""; 502 } elseif((array_key_exists('default_value',$cfg_data[$i])) AND (!is_array($cfg_data[$i]['default_value']))) { 503 $custom_cfg_data[$key]['value'] = $cfg_data[$i]['default_value']; 504 } 505 } 506 if ($cfg_data[$i]['type'] == "group") { 507 $group_count++; 508 $template_variables_array[$group_count]['title'] = $cfg_data[$i]['description']; 509 $variables_count = 0; 510 } elseif ($cfg_data[$i]['type'] == "loop") { 511 $group_count++; 512 $template_variables_array[$group_count]['title'] = $cfg_data[$i]['description']; 513 $loop_start = $cfg_data[$i]['loop_start']; 514 $loop_end = $cfg_data[$i]['loop_end']; 515 $variables_count = 0; 516 for($a=$loop_start;$a<=$loop_end;$a++) { 517 foreach($cfg_data[$i]['data']['item'] as $items) { 518 if(isset($items['description'])) { 519 $items['description'] = str_replace('{$count}',$a,$items['description']); 520 $key = str_replace('$','',$items['variable'])."_".$a; 521 if(array_key_exists($key,$custom_cfg_data)) { 522 $custom_cfg_data[$key]['value'] = $custom_cfg_data[$key][$a]; 523 } else { 524 $custom_cfg_data[$key]['value'] = ''; 501 $variables_count = 0; 502 503 foreach($cfg_data as $data) { 504 $data = $this->fix_single_array_keys($data['category']); 505 foreach($data as $cats) { 506 //We force the start of a new 'section' by increasing group_count and resetting variables_count to zero 507 if($cats['name'] != 'lines') { 508 $key = $this->arraysearchrecursive($cats['name'], $template_variables_array, 'title'); 509 if(is_array($key)) { 510 $group_count == $key[0]; 511 $num = count($this->fix_single_array_keys($template_variables_array[$group_count]['data'])); 512 $variables_count == $num; 513 } else { 514 if($admin) { 515 $group_count++; 516 $variables_count = 0; 517 } 518 } 519 $template_variables_array[$group_count]['title'] = $cats['name']; 520 } 521 $cats = $this->fix_single_array_keys($cats['subcategory']); 522 foreach($cats as $subcats) { 523 $items = $this->fix_single_array_keys($subcats['item']); 524 foreach($items as $config_options) { 525 if($admin) { 526 //Administration View Only 527 switch ($config_options['type']) { 528 case "loop_line_options": 529 for($a=1;$a <= $max_lines; $a++) { 530 $group_count++; 531 $variables_count = 0; 532 $template_variables_array[$group_count]['title'] = "Line Options for Line ".$a; 533 foreach($config_options['data']['item'] as $items) { 534 if(isset($items['description'])) { 535 $items['description'] = str_replace('{$count}',$a,$items['description']); 536 $key = "line|".$a."|".str_replace('$','',$items['variable']); 537 if(array_key_exists($key,$custom_cfg_data)) { 538 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 539 } else { 540 $custom_cfg_data[$key] = str_replace('{$count}', $a, $this->fix_single_array_keys($items['default_value'])); 541 } 542 } 543 $items[$variables_count] = $items; 544 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 545 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 546 $variables_count++; 547 } 548 } 549 continue 2; 550 case "loop": 551 //We force the start of a new 'section' by increasing group_count and resetting variables_count to zero 552 $loop_start = $config_options['loop_start']; 553 $loop_end = $config_options['loop_end']; 554 for($a=$loop_start;$a<=$loop_end;$a++) { 555 foreach($config_options['data']['item'] as $items) { 556 if(isset($items['description'])) { 557 $items['description'] = str_replace('{$count}',$a,$items['description']); 558 $key = "loop|".str_replace('$','',$items['variable'])."_".$a; 559 if(array_key_exists($key,$custom_cfg_data)) { 560 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 561 } else { 562 $custom_cfg_data[$key] = str_replace('{$count}', $a, $this->fix_single_array_keys($items['default_value'])); 563 } 564 } 565 $items[$variables_count] = $items; 566 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 567 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 568 $variables_count++; 569 } 570 } 571 continue 2; 572 } 573 } else { 574 //ARI View Only 575 $template_variables_array[$group_count]['title'] = "Your Phone Settings"; 576 switch ($config_options['type']) { 577 case "loop_line_options": 578 //$a is the line number 579 $sql = "SELECT line FROM endpointman_line_list WHERE ext = ".$ext; 580 $a = $this->db->getOne($sql); 581 $template_variables_array[$group_count]['title'] = "Line Options for Line ".$a; 582 foreach($config_options['data']['item'] as $items) { 583 if(isset($items['description'])) { 584 $items['description'] = str_replace('{$count}',$a,$items['description']); 585 $key = "line|".$a."|".str_replace('$','',$items['variable']); 586 if(array_key_exists($key,$custom_cfg_data)) { 587 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 588 } else { 589 $custom_cfg_data[$key] = str_replace('{$count}', $a, $this->fix_single_array_keys($items['default_value'])); 590 } 591 } 592 if(isset($custom_cfg_data_ari[$key])) { 593 $items[$variables_count] = $items; 594 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 595 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 596 $variables_count++; 597 } 598 } 599 $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; 600 $variables_count++; 601 continue 2; 602 case "loop": 603 $template_variables_array[$group_count]['data'][$variables_count]['type'] = "break"; 604 $variables_count++; 605 $loop_start = $config_options['loop_start']; 606 $loop_end = $config_options['loop_end']; 607 for($a=$loop_start;$a<=$loop_end;$a++) { 608 foreach($config_options['data']['item'] as $items) { 609 if(isset($items['description'])) { 610 $items['description'] = str_replace('{$count}',$a,$items['description']); 611 $key = "loop|".str_replace('$','',$items['variable'])."_".$a; 612 if(array_key_exists($key,$custom_cfg_data)) { 613 $custom_cfg_data[$key] = $custom_cfg_data[$key]; 614 } else { 615 $custom_cfg_data[$key] = ''; 616 } 617 } 618 if(isset($custom_cfg_data_ari[$key])) { 619 $items[$variables_count] = $items; 620 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$items,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 621 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 622 $variables_count++; 623 } 624 } 625 } 626 continue 2; 627 } 628 } 629 //Both Views 630 switch ($config_options['type']) { 631 case "break": 632 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$config_options,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 633 $variables_count++; 634 break; 635 default: 636 if(array_key_exists('variable',$config_options)) { 637 $key = str_replace('$','',$config_options['variable']); 638 //TODO: Move this into the sync function 639 //Checks to see if values are defined in the database, if not then we assume this is a new option and we need a default value here! 640 if(!isset($custom_cfg_data[$key])) { 641 //xml2array will take values that have no data and turn them into arrays, we want to avoid the word 'array' as a default value, so we blank it out here if we are an array 642 if((array_key_exists('default_value',$config_options)) AND (is_array($config_options['default_value']))) { 643 $custom_cfg_data[$key] = ""; 644 } elseif((array_key_exists('default_value',$config_options)) AND (!is_array($config_options['default_value']))) { 645 $custom_cfg_data[$key] = $config_options['default_value']; 646 } 647 } 648 if((!$admin) AND (isset($custom_cfg_data_ari[$key]))) { 649 $custom_cfg_data[$key] = $user_cfg_data[$key]; 650 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$config_options,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 651 $variables_count++; 652 } elseif($admin) { 653 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($variables_count,$config_options,$key,$custom_cfg_data,$admin,$user_cfg_data,$custom_cfg_data_ari); 654 $variables_count++; 655 } 525 656 } 526 } 527 $items[$i] = $items; 528 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($i,$items,$key,$custom_cfg_data,$admin,$user_cfg_data); 529 $template_variables_array[$group_count]['data'][$variables_count]['looping'] = TRUE; 530 $variables_count++; 657 break; 531 658 } 532 } 533 } else { 534 if(!isset($variables_count)) { 535 $variables_count = 0; 536 } 537 $template_variables_array[$group_count]['data'][$variables_count] = $this->generate_form_data($i,$cfg_data,$key,$custom_cfg_data,$admin,$user_cfg_data); 538 $variables_count++; 659 continue; 660 } 539 661 } 540 662 } … … 551 673 * @return array 552 674 */ 553 function generate_form_data ($i,$cfg_data,$key,$custom_cfg_data,$admin=FALSE,$user_cfg_data) { 554 if ($cfg_data[$i]['type'] == "input") { 555 if((!$admin) && (isset($user_cfg_data[$key]['value']))) { 556 $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; 557 } 558 $template_variables_array['type'] = "input"; 559 $template_variables_array['key'] = $key; 560 $template_variables_array['value'] = $custom_cfg_data[$key]['value']; 561 $template_variables_array['description'] = $cfg_data[$i]['description']; 562 } elseif ($cfg_data[$i]['type'] == "radio") { 563 if((!$admin) && (isset($user_cfg_data[$key]['value']))) { 564 $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; 565 } 566 $num = $custom_cfg_data[$key]['value']; 567 $template_variables_array['type'] = "radio"; 568 $template_variables_array['key'] = $key; 569 $template_variables_array['description'] = $cfg_data[$i]['description']; 570 $z = 0; 571 while($z < count($cfg_data[$i]['data'])) { 572 $template_variables_array['data'][$z]['key'] = $key; 573 $template_variables_array['data'][$z]['value'] = $cfg_data[$i]['data'][$z]['value']; 574 $template_variables_array['data'][$z]['description'] = $cfg_data[$i]['data'][$z]['text']; 575 if ($cfg_data[$i]['data'][$z]['value'] == $num) { 576 $template_variables_array['data'][$z]['checked'] = 'checked'; 577 } 578 $z++; 579 } 580 } elseif ($cfg_data[$i]['type'] == "list") { 581 if((!$admin) && (isset($user_cfg_data[$key]['value']))) { 582 $custom_cfg_data[$key]['value'] = $user_cfg_data[$key]['value']; 583 } 584 $num = $custom_cfg_data[$key]['value']; 585 $template_variables_array['type'] = "list"; 586 $template_variables_array['key'] = $key; 587 $template_variables_array['description'] = $cfg_data[$i]['description']; 588 $z = 0; 589 while($z < count($cfg_data[$i]['data'])) { 590 $template_variables_array['data'][$z]['value'] = $cfg_data[$i]['data'][$z]['value']; 591 $template_variables_array['data'][$z]['description'] = $cfg_data[$i]['data'][$z]['text']; 592 if ($cfg_data[$i]['data'][$z]['value'] == $num) { 593 $template_variables_array['data'][$z]['selected'] = 'selected'; 594 } 595 $z++; 596 } 597 } elseif ($cfg_data[$i]['type'] == "break") { 598 $template_variables_array['type'] = "break"; 599 } 600 if(($this->global_cfg['enable_ari']) AND ($admin) AND ($cfg_data[$i]['type'] != "break") AND ($cfg_data[$i]['type'] != "group")) { 675 function generate_form_data ($i,$cfg_data,$key=NULL,$custom_cfg_data=NULL,$admin=FALSE,$user_cfg_data=NULL,$custom_cfg_data_ari=NULL) { 676 switch ($cfg_data['type']) { 677 case "input": 678 if((!$admin) && (isset($user_cfg_data[$key]))) { 679 $custom_cfg_data[$key] = $user_cfg_data[$key]; 680 } 681 $template_variables_array['type'] = "input"; 682 if(isset($cfg_data['max_chars'])) { 683 $template_variables_array['max_chars'] = $cfg_data['max_chars']; 684 } 685 $template_variables_array['key'] = $key; 686 $template_variables_array['value'] = $custom_cfg_data[$key]; 687 $template_variables_array['description'] = $cfg_data['description']; 688 break; 689 case "radio": 690 if((!$admin) && (isset($user_cfg_data[$key]))) { 691 $custom_cfg_data[$key] = $user_cfg_data[$key]; 692 } 693 $num = $custom_cfg_data[$key]; 694 $template_variables_array['type'] = "radio"; 695 $template_variables_array['key'] = $key; 696 $template_variables_array['description'] = $cfg_data['description']; 697 $z = 0; 698 while($z < count($cfg_data['data'])) { 699 $template_variables_array['data'][$z]['key'] = $key; 700 $template_variables_array['data'][$z]['value'] = $cfg_data['data'][$z]['value']; 701 $template_variables_array['data'][$z]['description'] = $cfg_data['data'][$z]['text']; 702 if ($cfg_data['data'][$z]['value'] == $num) { 703 $template_variables_array['data'][$z]['checked'] = 'checked'; 704 } 705 $z++; 706 } 707 break; 708 case "list": 709 if((!$admin) && (isset($user_cfg_data[$key]))) { 710 $custom_cfg_data[$key] = $user_cfg_data[$key]; 711 } 712 $num = $custom_cfg_data[$key]; 713 $template_variables_array['type'] = "list"; 714 $template_variables_array['key'] = $key; 715 $template_variables_array['description'] = $cfg_data['description']; 716 $z = 0; 717 while($z < count($cfg_data['data'])) { 718 $template_variables_array['data'][$z]['value'] = $cfg_data['data'][$z]['value']; 719 $template_variables_array['data'][$z]['description'] = $cfg_data['data'][$z]['text']; 720 if (isset($cfg_data['data'][$z]['disable'])) { 721 $cfg_data['data'][$z]['disable'] = str_replace('{$count}', $z, $cfg_data['data'][$z]['disable']); 722 $template_variables_array['data'][$z]['disables'] = explode(",", $cfg_data['data'][$z]['disable']); 723 } 724 if (isset($cfg_data['data'][$z]['enable'])) { 725 $cfg_data['data'][$z]['enable'] = str_replace('{$count}', $z, $cfg_data['data'][$z]['enable']); 726 $template_variables_array['data'][$z]['enables'] = explode(",", $cfg_data['data'][$z]['enable']); 727 } 728 if ($cfg_data['data'][$z]['value'] == $num) { 729 $template_variables_array['data'][$z]['selected'] = 'selected'; 730 } 731 $z++; 732 } 733 break; 734 case "checkbox": 735 $template_variables_array['type'] = "NA"; 736 break; 737 case "file"; 738 $template_variables_array['type'] = "NA"; 739 break; 740 case "textarea": 741 $template_variables_array['type'] = "NA"; 742 break; 743 case "file": 744 $template_variables_array['type'] = "NA"; 745 break; 746 case "break": 747 if($admin) { 748 $template_variables_array['type'] = "break"; 749 } else { 750 $template_variables_array['type'] = "NA"; 751 } 752 break; 753 default: 754 $template_variables_array['type'] = "NA"; 755 break; 756 } 757 758 if(($this->global_cfg['enable_ari']) AND ($admin) AND ($cfg_data['type'] != "break") AND ($cfg_data['type'] != "group")) { 601 759 602 760 $template_variables_array['aried'] = 1; 603 761 $template_variables_array['ari']['key'] = $key; 604 if(isset($custom_cfg_data [$key]['ari'])) {762 if(isset($custom_cfg_data_ari[$key])) { 605 763 $template_variables_array['ari']['checked'] = "checked"; 606 764 } … … 630 788 $cfg_data = unserialize($row['template_data']); 631 789 $count = count($cfg_data); 632 for($i=0;$i<$count;$i++) { 633 if(array_key_exists('variable',$cfg_data[$i])) { 634 $temping = str_replace('$','',$cfg_data[$i]['variable']); 635 $temping_ari = "ari_" . $temping; 636 if(array_key_exists($temping, $_REQUEST)) { 637 $custom_cfg_data[$temping]['value'] = $_REQUEST[$temping]; 638 if(array_key_exists($temping_ari, $_REQUEST)) { 639 if($_REQUEST[$temping_ari] == "on") { 640 $custom_cfg_data[$temping]['ari'] = 1; 641 } 642 } 643 } 644 } elseif ($cfg_data[$i]['type'] == 'loop') { 645 $loop_start = $cfg_data[$i]['loop_start']; 646 $loop_end = $cfg_data[$i]['loop_end']; 647 $variables_count = 0; 648 for($a=$loop_start;$a<=$loop_end;$a++) { 649 foreach($cfg_data[$i]['data']['item'] as $items) { 650 if(isset($items['description'])) { 651 $items['description'] = str_replace('{$count}',$a,$items['description']); 652 $temping = str_replace('$','',$items['variable'])."_".$a; 790 791 $custom_cfg_data_ari = array(); 792 793 foreach($cfg_data as $data) { 794 $data = $this->fix_single_array_keys($data['category']); 795 foreach($data as $cats) { 796 $cats = $this->fix_single_array_keys($cats['subcategory']); 797 foreach($cats as $subcats) { 798 $items = $this->fix_single_array_keys($subcats['item']); 799 foreach($items as $config_options) { 800 if(array_key_exists('variable',$config_options)) { 801 $temping = str_replace('$','',$config_options['variable']); 653 802 $temping_ari = "ari_" . $temping; 654 803 if(array_key_exists($temping, $_REQUEST)) { 655 $custom_cfg_data[$temping] [$a]= $_REQUEST[$temping];804 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 656 805 if(array_key_exists($temping_ari, $_REQUEST)) { 657 806 if($_REQUEST[$temping_ari] == "on") { 658 $custom_cfg_data[$temping]['ari'] = 1; 807 $custom_cfg_data_ari[$temping] = 1; 808 } 809 } 810 } 811 } elseif ($config_options['type'] == 'loop') { 812 $loop_start = $config_options['loop_start']; 813 $loop_end = $config_options['loop_end']; 814 $variables_count = 0; 815 for($a=$loop_start;$a<=$loop_end;$a++) { 816 foreach($config_options['data']['item'] as $items) { 817 if(isset($items['description'])) { 818 $items['description'] = str_replace('{$count}',$a,$items['description']); 819 $temping = "loop|".str_replace('$','',$items['variable'])."_".$a; 820 $temping_ari = "ari_" . $temping; 821 if(array_key_exists($temping, $_REQUEST)) { 822 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 823 if(array_key_exists($temping_ari, $_REQUEST)) { 824 if($_REQUEST[$temping_ari] == "on") { 825 $custom_cfg_data_ari[$temping] = 1; 826 } 827 } 828 } 829 } 830 } 831 } 832 } elseif ($config_options['type'] == 'loop_line_options') { 833 for($a=1;$a<=3;$a++) { 834 foreach($config_options['data']['item'] as $items) { 835 if(isset($items['description'])) { 836 $items['description'] = str_replace('{$count}',$a,$items['description']); 837 $temping = "line|".$a."|".str_replace('$','',$items['variable']); 838 $temping_ari = "ari_" . $temping; 839 if(array_key_exists($temping, $_REQUEST)) { 840 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 841 if(array_key_exists($temping_ari, $_REQUEST)) { 842 if($_REQUEST[$temping_ari] == "on") { 843 $custom_cfg_data_ari[$temping] = 1; 844 } 845 } 846 } 659 847 } 660 848 } … … 667 855 668 856 $config_files = explode(",",$row['config_files']); 857 669 858 $i = 0; 670 859 while($i < count($config_files)) { 671 860 $config_files[$i] = str_replace(".","_",$config_files[$i]); 672 861 if(isset($_REQUEST[$config_files[$i]])) { 862 $_REQUEST[$config_files[$i]] = explode("_",$_REQUEST[$config_files[$i]], 2); 863 $_REQUEST[$config_files[$i]] = $_REQUEST[$config_files[$i]][0]; 673 864 if($_REQUEST[$config_files[$i]] > 0) { 674 865 $config_files_selected[$config_files[$i]] = $_REQUEST[$config_files[$i]]; … … 677 868 $i++; 678 869 } 870 679 871 if(!isset($config_files_selected)) { 680 872 $config_files_selected = ""; … … 682 874 $config_files_selected = serialize($config_files_selected); 683 875 } 684 $save = serialize($custom_cfg_data); 876 $custom_cfg_data_temp['data'] = $custom_cfg_data; 877 $custom_cfg_data_temp['ari'] = $custom_cfg_data_ari; 878 $save = serialize($custom_cfg_data_temp); 685 879 686 880 if($custom == "0") { … … 709 903 } 710 904 711 return($location); 905 if(isset($_REQUEST['silent_mode'])) { 906 echo '<script language="javascript" type="text/javascript">window.close();</script>'; 907 } else { 908 return($location); 909 } 712 910 713 911 } … … 717 915 * @param array $phone_info Everything from get_phone_info 718 916 */ 719 function prepare_configs($phone_info ) {917 function prepare_configs($phone_info,$reboot=TRUE) { 720 918 if(!class_exists('ProvisionerConfig')) { 721 919 require(PHONE_MODULES_PATH.'setup.php'); … … 729 927 $provisioner_lib->root_dir = PHONE_MODULES_PATH; 730 928 $provisioner_lib->engine = 'asterisk'; 929 $provisioner_lib->engine_location = $this->global_cfg['asterisk_location']; 731 930 $provisioner_lib->system = 'unix'; 732 931 … … 749 948 $provisioner_lib->server[1]['port'] = 5060; 750 949 751 //Provide alternate Configuration file instead of the one from the hard drive752 950 $temp = ""; 753 if(!empty($phone_info['config_files_override'])) { 754 $temp = unserialize($phone_info['config_files_override']); 755 foreach($temp as $list) { 756 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; 757 $res =& $this->db->query($sql); 758 if($res->numRows()) { 759 $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); 760 $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; 951 $template_data = unserialize($phone_info['template_data']); 952 $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']); 953 if($phone_info['template_id'] > 0) { 954 $global_custom_cfg_data = unserialize($phone_info['template_data_info']['global_custom_cfg_data']); 955 //Provide alternate Configuration file instead of the one from the hard drive 956 if(!empty($phone_info['template_data_info']['config_files_override'])) { 957 $temp = unserialize($phone_info['template_data_info']['config_files_override']); 958 foreach($temp as $list) { 959 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; 960 $res =& $this->db->query($sql); 961 if($res->numRows()) { 962 $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); 963 $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; 964 } 965 } 966 } 967 } else { 968 $global_custom_cfg_data = unserialize($phone_info['global_custom_cfg_data']); 969 //Provide alternate Configuration file instead of the one from the hard drive 970 if(!empty($phone_info['config_files_override'])) { 971 $temp = unserialize($phone_info['config_files_override']); 972 foreach($temp as $list) { 973 $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; 974 $res =& $this->db->query($sql); 975 if($res->numRows()) { 976 $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); 977 $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; 978 } 979 } 980 } 981 } 982 983 if (!empty($global_custom_cfg_data)) { 984 if(array_key_exists('data', $global_custom_cfg_data)) { 985 $global_custom_cfg_ari = $global_custom_cfg_data['ari']; 986 $global_custom_cfg_data = $global_custom_cfg_data['data']; 987 } else { 988 $global_custom_cfg_data = array(); 989 $global_custom_cfg_ari = array(); 990 } 991 } 992 993 $new_template_data = array(); 994 $line_ops = array(); 995 if(is_array($global_custom_cfg_data)) { 996 foreach($global_custom_cfg_data as $key => $data) { 997 $full_key = $key; 998 $key = explode('|',$key); 999 $count = count($key); 1000 switch($count) { 1001 case 1: 1002 if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 1003 $new_template_data[$full_key] = $global_user_cfg_data[$full_key]; 1004 } else { 1005 $new_template_data[$full_key] = $global_custom_cfg_data[$full_key]; 1006 } 1007 break; 1008 case 2: 1009 $breaks = explode('_',$key[1]); 1010 if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 1011 $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key]; 1012 } else { 1013 $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key]; 1014 } 1015 break; 1016 case 3: 1017 if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { 1018 $line_ops[$key[1]][$key[2]] = $global_user_cfg_data[$full_key]; 1019 } else { 1020 $line_ops[$key[1]][$key[2]] = $global_custom_cfg_data[$full_key]; 1021 } 1022 break; 761 1023 } 762 1024 } … … 766 1028 foreach($phone_info['line'] as $line) { 767 1029 $provisioner_lib->lines[$line['line']] = array('ext' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description']); 768 } 769 770 $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']); 771 772 if(is_array($phone_info['template_data'])) { 773 $template_data = unserialize($phone_info['template_data']['global_custom_cfg_data']); 774 } else { 775 $template_data = unserialize($phone_info['global_custom_cfg_data']); 776 } 777 778 $new_template_data = array(); 779 if(is_array($template_data)) { 780 foreach($template_data as $key => $data) { 781 if(array_key_exists('value', $data)) { 782 if((isset($template_data[$key]['ari'])) && (isset($global_user_cfg_data[$key]['value']))) { 783 $new_template_data[$key] = $global_user_cfg_data[$key]['value']; 784 } else { 785 $new_template_data[$key] = $data['value']; 786 } 787 } else { 788 $key = explode('_',$key); 789 $new_template_data[$key[0]][$key[2]][$key[1]] = $data[$key[2]]; 790 } 1030 if(isset($line_ops[$line['line']])) { 1031 $provisioner_lib->lines[$line['line']]['options'] = $line_ops[$line['line']]; 791 1032 } 792 1033 } … … 795 1036 //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included 796 1037 //line 'global' will set variables that aren't line dependant 1038 797 1039 $provisioner_lib->options = $new_template_data; 798 1040 … … 827 1069 if(is_dir(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data)) { 828 1070 if(!file_exists($this->global_cfg['config_location'].$data)) { 829 mkdir($this->global_cfg['config_location'].$data, 0777); 1071 if (!@mkdir($this->global_cfg['config_location'].$data, 0777)) { 1072 $this->error['parse_configs'] = "Could Not Create Directory: ".$data; 1073 } 830 1074 } 831 1075 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/"); … … 836 1080 $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); 837 1081 if(!file_exists($this->global_cfg['config_location'].$data."/".$dir)) { 838 mkdir($this->global_cfg['config_location'].$data."/".$dir, 0777); 1082 if (!@mkdir($this->global_cfg['config_location'].$data."/".$dir, 0777)) { 1083 $this->error['parse_configs'] = "Could Not Create Directory: ".$data."/".$dir; 1084 } 839 1085 } 840 1086 } else { 841 1087 $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); 842 copy($file, $this->global_cfg['config_location'].$data."/".$dir); 843 chmod($this->global_cfg['config_location'].$data."/".$dir, 0777); 1088 if(!@copy($file, $this->global_cfg['config_location'].$data."/".$dir)) { 1089 $this->error['parse_configs'] = "Could Not Copy File: ".$data."/".$dir; 1090 } else { 1091 chmod($this->global_cfg['config_location'].$data."/".$dir, 0777); 1092 } 844 1093 } 845 1094 } … … 863 1112 } 864 1113 } 865 $provisioner_lib->reboot(); 1114 if($reboot) { 1115 $provisioner_lib->reboot(); 1116 } 866 1117 } 867 1118 … … 936 1187 * @param int $id Product ID 937 1188 */ 938 function remove_firmware($id =NULL) {1189 function remove_firmware($id) { 939 1190 $sql = "SELECT firmware_files FROM endpointman_product_list WHERE id =". $id; 940 1191 $files = $this->db->getOne($sql); … … 974 1225 $file = basename($filename); 975 1226 $list[$i] = $file; 976 copy($filename, $this->global_cfg['config_location'].$file); 1227 if (!@copy($filename, $this->global_cfg['config_location'].$file)) { 1228 echo "<BR />--Failed To Copy $file...<BR />"; 1229 $copy_error = TRUE; 1230 } 977 1231 $i++; 978 1232 } … … 980 1234 $sql = "UPDATE endpointman_product_list SET firmware_vers = '".$temp['data']['firmware_ver']."', firmware_files = '".$list."' WHERE id = ". $row['id']; 981 1235 $this->db->query($sql); 982 echo "Done!"; 1236 if(isset($copy_error)) { 1237 echo "Copy Error Detected! Aborting Install!"; 1238 $this->remove_firmware($product_id); 1239 echo "<BR />Please Check Directory/Permissions"; 1240 } else { 1241 echo "Done!"; 1242 } 983 1243 } else { 984 1244 echo "Your Firmware is already up to date"; … … 1158 1418 } 1159 1419 1160 /** 1161 * This will install or updated a brand package (which is the same thing to this) 1162 * Still needs way to determine when models move...perhaps another function? 1163 * @param <type> $id 1164 */ 1165 function update_brand($id = NULL) { 1420 function download_brand($id) { 1166 1421 $row =& $this->db->getAll('SELECT * FROM endpointman_brand_list WHERE id ='.$id, array(), DB_FETCHMODE_ASSOC); 1167 1168 1422 echo "Downloading Brand XML....."; 1169 1423 $result = $this->download_xml(UPDATE_PATH .$row[0]['directory']. "/".$row[0]['directory'].".xml","endpoint/".$row[0]['directory']); 1170 1424 if($result) { 1171 1425 echo "Done!<br/>"; 1172 1173 1426 $temp = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$row[0]['directory'].'/brand_data.xml'); 1174 1175 $brand_name = $temp['data']['brands']['name']; 1176 $brand_id = $temp['data']['brands']['brand_id']; 1177 $brand_version = $temp['data']['brands']['version']; 1178 $brand_last_mod = $temp['data']['brands']['last_modified']; 1179 $package = $temp['data']['brands']['package']; 1180 1181 echo "<div style='float: left'>Downloading Brand Package...</div><div style='float: left' id=\"DivExample\">.</div>"; 1182 $this->download_file_with_progress_bar(UPDATE_PATH.$row[0]['directory'].'/'.$package, PHONE_MODULES_PATH."temp/".$package); 1183 echo "<script type='text/javascript'>document.getElementById('DivExample').innerHTML='Done!';</script><br />"; 1184 1185 echo "Extracting Tarball........"; 1186 exec("tar -xvf ".PHONE_MODULES_PATH.'temp/'. $package ." -C ".PHONE_MODULES_PATH."temp/"); 1187 echo "Done!<br />"; 1188 1189 echo "Creating Directory Structure/Moving Files..............."; 1190 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/"); 1191 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); 1192 // could use CHILD_FIRST if you so wish 1193 1194 foreach ($iterator as $file) { 1195 if(is_dir($file)) { 1427 $this->update_brand($temp); 1428 } else { 1429 echo "<br/>Error Connecting to the Package Repository. Module not installed. Please Try again later.<br/>You Can Also Manually Update The Repository By Downloading Files here: <a href='http://www.provisioner.net/release.html' target='_blank'>Release Repo</a><br />Then Use Manual Upload in Advanced Settings"; 1430 } 1431 } 1432 1433 /** 1434 * This will install or updated a brand package (which is the same thing to this) 1435 * Still needs way to determine when models move...perhaps another function? 1436 * @param <type> $id 1437 */ 1438 function update_brand($temp) { 1439 $row[0]['directory'] = $temp['data']['brands']['directory']; 1440 $brand_name = $temp['data']['brands']['name']; 1441 $brand_id = $temp['data']['brands']['brand_id']; 1442 $brand_version = $temp['data']['brands']['version']; 1443 $brand_last_mod = $temp['data']['brands']['last_modified']; 1444 $package = $temp['data']['brands']['package']; 1445 1446 echo "<div style='float: left'>Downloading Brand Package...</div><div style='float: left' id=\"DivExample\">.</div>"; 1447 $this->download_file_with_progress_bar(UPDATE_PATH.$row[0]['directory'].'/'.$package, PHONE_MODULES_PATH."temp/".$package); 1448 echo "<script type='text/javascript'>document.getElementById('DivExample').innerHTML='Done!';</script><br />"; 1449 1450 echo "Extracting Tarball........"; 1451 exec("tar -xvf ".PHONE_MODULES_PATH.'temp/'. $package ." -C ".PHONE_MODULES_PATH."temp/"); 1452 echo "Done!<br />"; 1453 1454 echo "Creating Directory Structure/Moving Files..............."; 1455 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/"); 1456 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); 1457 // could use CHILD_FIRST if you so wish 1458 1459 foreach ($iterator as $file) { 1460 if(is_dir($file)) { 1461 $dir = str_replace(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/", "", $file); 1462 if(!file_exists(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir)) { 1463 mkdir(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir,0764); 1464 } 1465 } else { 1466 if(basename($file) != "brand_data.xml") { 1196 1467 $dir = str_replace(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/", "", $file); 1197 if(!file_exists(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir)) { 1198 mkdir(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir,0764); 1199 } 1468 rename($file, PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir); 1469 chmod(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir,0764); 1470 } 1471 } 1472 } 1473 echo "Done!<br />"; 1474 1475 echo "Removing Temporary Files.............."; 1476 $this->deltree(PHONE_MODULES_PATH."temp/" .$row[0]['directory']); 1477 unlink(PHONE_MODULES_PATH.'temp/'. $package); 1478 echo "Done!<br />"; 1479 1480 $last_mod = ""; 1481 $temp['data']['brands']['family_list']['family'] = $this->fix_single_array_keys($temp['data']['brands']['family_list']['family']); 1482 foreach($temp['data']['brands']['family_list']['family'] as $family_list) { 1483 echo "Updating Family Lines.................<br/>"; 1484 $last_mod = max($last_mod, $family_list['last_modified']); 1485 1486 $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$row[0]['directory'].'/'.$family_list['directory'].'/family_data.xml'); 1487 $data =& $this->db->getOne("SELECT id FROM endpointman_product_list WHERE id='".$brand_id.$family_line_xml['data']['id']."'", array(), DB_FETCHMODE_ASSOC); 1488 $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); 1489 if($data) { 1490 $sql = "UPDATE endpointman_product_list SET short_name = '".$short_name."', long_name = '".$family_line_xml['data']['name']."', cfg_ver = '".$family_line_xml['data']['version']."', config_files='".$family_line_xml['data']['configuration_files']."' WHERE id = '".$brand_id.$family_line_xml['data']['id']."'"; 1491 } else { 1492 $sql = "INSERT INTO endpointman_product_list (`id`, `brand`, `short_name`, `long_name`, `cfg_dir`, `cfg_ver`, `config_files`, `hidden`) VALUES ('".$brand_id.$family_line_xml['data']['id']."', '".$brand_id."', '".$short_name."', '".$family_line_xml['data']['name']."', '".$family_line_xml['data']['directory']."', '".$family_line_xml['data']['version']."','".$family_line_xml['data']['configuration_files']."', '0')"; 1493 } 1494 1495 $this->db->query($sql); 1496 $family_line_xml['data']['model_list'] = $this->fix_single_array_keys($family_line_xml['data']['model_list']); 1497 echo "--Updating Model Lines................<br/>"; 1498 foreach($family_line_xml['data']['model_list'] as $model_list) { 1499 if(is_array($model_list['template_data']['files'])) { 1500 $template_list = implode(",",$model_list['template_data']['files']); 1200 1501 } else { 1201 if(basename($file) != "brand_data.xml") { 1202 $dir = str_replace(PHONE_MODULES_PATH."temp/".$row[0]['directory']."/", "", $file); 1203 rename($file, PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir); 1204 chmod(PHONE_MODULES_PATH."endpoint/".$row[0]['directory']."/".$dir,0764); 1205 } 1206 } 1207 } 1208 echo "Done!<br />"; 1209 1210 echo "Removing Temporary Files.............."; 1211 $this->deltree(PHONE_MODULES_PATH."temp/" .$row[0]['directory']); 1212 unlink(PHONE_MODULES_PATH.'temp/'. $package); 1213 echo "Done!<br />"; 1214 1215 $last_mod = ""; 1216 $temp['data']['brands']['family_list']['family'] = $this->fix_single_array_keys($temp['data']['brands']['family_list']['family']); 1217 foreach($temp['data']['brands']['family_list']['family'] as $family_list) { 1218 echo "Updating Family Lines.................<br/>"; 1219 $last_mod = max($last_mod, $family_list['last_modified']); 1220 1221 $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$row[0]['directory'].'/'.$family_list['directory'].'/family_data.xml'); 1222 $data =& $this->db->getOne("SELECT id FROM endpointman_product_list WHERE id='".$brand_id.$family_line_xml['data']['id']."'", array(), DB_FETCHMODE_ASSOC); 1223 $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); 1224 if($data) { 1225 $sql = "UPDATE endpointman_product_list SET short_name = '".$short_name."', long_name = '".$family_line_xml['data']['name']."', cfg_ver = '".$family_line_xml['data']['version']."', config_files='".$family_line_xml['data']['configuration_files']."' WHERE id = '".$brand_id.$family_line_xml['data']['id']."'"; 1502 $template_list = $model_list['template_data']['files']; 1503 } 1504 1505 $model_final_id = $brand_id.$family_line_xml['data']['id'].$model_list['id']; 1506 $sql = 'SELECT id, global_custom_cfg_data, global_user_cfg_data FROM endpointman_mac_list WHERE model = '.$model_final_id; 1507 $old_data = NULL; 1508 $old_data = $this->db->getAll($sql, array(), DB_FETCHMODE_ASSOC); 1509 foreach($old_data as $data) { 1510 $global_custom_cfg_data = unserialize($data['global_custom_cfg_data']); 1511 if((is_array($global_custom_cfg_data)) AND (!array_key_exists('data', $global_custom_cfg_data))) { 1512 echo "----Old Data Detected! Migrating......"; 1513 $new_data = array(); 1514 $new_ari = array(); 1515 foreach($global_custom_cfg_data as $key => $old_keys) { 1516 if(array_key_exists('value', $old_keys)) { 1517 $new_data[$key] = $old_keys['value']; 1518 } else { 1519 $breaks = explode("_", $key); 1520 $new_data["loop|".$key] = $old_keys[$breaks[2]]; 1521 } 1522 if(array_key_exists('ari', $old_keys)) { 1523 $new_ari[$key] = 1; 1524 } 1525 } 1526 $final_data = array(); 1527 $final_data['data'] = $new_data; 1528 $final_data['ari'] = $new_ari; 1529 $final_data = serialize($final_data); 1530 $sql = "UPDATE endpointman_mac_list SET global_custom_cfg_data = '".$final_data."' WHERE id =".$data['id']; 1531 $this->db->query($sql); 1532 echo "Done!<br/>"; 1533 } 1534 1535 $global_user_cfg_data = unserialize($data['global_user_cfg_data']); 1536 $old_check = FALSE; 1537 if(is_array($global_user_cfg_data)) { 1538 foreach($global_user_cfg_data as $stuff) { 1539 if(is_array($stuff)) { 1540 if(array_key_exists('value', $stuff)) { 1541 $old_check = TRUE; 1542 break; 1543 } else { 1544 break; 1545 } 1546 } else { 1547 break; 1548 } 1549 } 1550 } 1551 if((is_array($global_user_cfg_data)) AND ($old_check)) { 1552 echo "Old Data Detected! Migrating......"; 1553 $new_data = array(); 1554 foreach($global_user_cfg_data as $key => $old_keys) { 1555 if(array_key_exists('value', $old_keys)) { 1556 $exploded = explode("_",$key); 1557 $counted = count($exploded); 1558 $counted = $counted - 1; 1559 if(is_numeric($exploded[$counted])) { 1560 $key = "loop|".$key; 1561 } 1562 $new_data[$key] = $old_keys['value']; 1563 } 1564 } 1565 $final_data = serialize($new_data); 1566 $sql = "UPDATE endpointman_mac_list SET global_user_cfg_data = '".$final_data."' WHERE id =".$data['id']; 1567 $this->db->query($sql); 1568 echo "Done!<br/>"; 1569 } 1570 } 1571 $old_data = NULL; 1572 $sql = 'SELECT id, global_custom_cfg_data FROM endpointman_template_list WHERE model_id = '.$model_final_id; 1573 $old_data = $this->db->getAll($sql, array(), DB_FETCHMODE_ASSOC); 1574 foreach($old_data as $data) { 1575 $global_custom_cfg_data = unserialize($data['global_custom_cfg_data']); 1576 if((is_array($global_custom_cfg_data)) AND (!array_key_exists('data', $global_custom_cfg_data))) { 1577 echo "Old Data Detected! Migrating......"; 1578 $new_data = array(); 1579 $new_ari = array(); 1580 foreach($global_custom_cfg_data as $key => $old_keys) { 1581 if(array_key_exists('value', $old_keys)) { 1582 $new_data[$key] = $old_keys['value']; 1583 } else { 1584 $breaks = explode("_", $key); 1585 $new_data["loop|".$key] = $old_keys[$breaks[2]]; 1586 } 1587 if(array_key_exists('ari', $old_keys)) { 1588 $new_ari[$key] = 1; 1589 } 1590 } 1591 $final_data = array(); 1592 $final_data['data'] = $new_data; 1593 $final_data['ari'] = $new_ari; 1594 $final_data = serialize($final_data); 1595 $sql = "UPDATE endpointman_template_list SET global_custom_cfg_data = '".$final_data."' WHERE id =".$data['id']; 1596 $this->db->query($sql); 1597 echo "Done!<br/>"; 1598 } 1599 } 1600 1601 $m_data =& $this->db->getOne("SELECT id FROM endpointman_model_list WHERE id='".$brand_id.$family_line_xml['data']['id'].$model_list['id']."'", array(), DB_FETCHMODE_ASSOC); 1602 if($m_data) { 1603 $sql = "UPDATE endpointman_model_list SET max_lines = '".$model_list['lines']."', model = '".$model_list['model']."', template_list = '".$template_list."' WHERE id = '".$brand_id.$family_line_xml['data']['id'].$model_list['id']."'"; 1226 1604 } else { 1227 $sql = "INSERT INTO endpointman_product_list (`id`, `brand`, `short_name`, `long_name`, `cfg_dir`, `cfg_ver`, `config_files`, `hidden`) VALUES ('".$brand_id.$family_line_xml['data']['id']."', '".$brand_id."', '".$short_name."', '".$family_line_xml['data']['name']."', '".$family_line_xml['data']['directory']."', '".$family_line_xml['data']['version']."','".$family_line_xml['data']['configuration_files']."', '0')"; 1228 } 1229 1605 $sql = "INSERT INTO endpointman_model_list (`id`, `brand`, `model`, `max_lines`, `product_id`, `template_list`, `enabled`, `hidden`) VALUES ('".$brand_id.$family_line_xml['data']['id'].$model_list['id']."', '".$brand_id."', '".$model_list['model']."', '".$model_list['lines']."', '".$brand_id.$family_line_xml['data']['id']."', '".$template_list."', '0', '0')"; 1606 } 1230 1607 $this->db->query($sql); 1231 $family_line_xml['data']['model_list'] = $this->fix_single_array_keys($family_line_xml['data']['model_list']); 1232 echo "--Updating Model Lines................<br/>"; 1233 foreach($family_line_xml['data']['model_list'] as $model_list) { 1234 if(is_array($model_list['template_data']['files'])) { 1235 $template_list = implode(",",$model_list['template_data']['files']); 1236 } else { 1237 $template_list = $model_list['template_data']['files']; 1238 } 1239 $m_data =& $this->db->getOne("SELECT id FROM endpointman_model_list WHERE id='".$brand_id.$family_line_xml['data']['id'].$model_list['id']."'", array(), DB_FETCHMODE_ASSOC); 1240 if($m_data) { 1241 $sql = "UPDATE endpointman_model_list SET max_lines = '".$model_list['lines']."', model = '".$model_list['model']."', template_list = '".$template_list."' WHERE id = '".$brand_id.$family_line_xml['data']['id'].$model_list['id']."'"; 1242 } else { 1243 $sql = "INSERT INTO endpointman_model_list (`id`, `brand`, `model`, `max_lines`, `product_id`, `template_list`, `enabled`, `hidden`) VALUES ('".$brand_id.$family_line_xml['data']['id'].$model_list['id']."', '".$brand_id."', '".$model_list['model']."', '".$model_list['lines']."', '".$brand_id.$family_line_xml['data']['id']."', '".$template_list."', '0', '0')"; 1244 } 1245 $this->db->query($sql); 1246 } 1247 } 1248 1249 $brand_version = max($last_mod, $brand_last_mod); 1250 echo "Updating data.........."; 1251 $sql = "UPDATE endpointman_brand_list SET name = '".$brand_name."', cfg_ver = '".$brand_version."', installed = 1, hidden = 0 WHERE id = ".$id; 1252 $this->db->query($sql); 1253 echo "Done!<br/>"; 1254 1255 } else { 1256 echo "<br/>Error Connecting to the Package Repository. Module not installed. Please Try again later.<br/>You Can Also Manually Update The Repository By Downloading Files here: <a href='http://www.provisioner.net/release.html' target='_blank'>Release Repo</a><br />Then Use Manual Upload in Advanced Settings"; 1257 } 1608 } 1609 } 1610 1611 $brand_version = max($last_mod, $brand_last_mod); 1612 echo "Updating data.........."; 1613 $sql = "UPDATE endpointman_brand_list SET name = '".$brand_name."', cfg_ver = '".$brand_version."', installed = 1, hidden = 0 WHERE id = ".$brand_id; 1614 $this->db->query($sql); 1615 echo "Done!<br/>"; 1258 1616 } 1259 1617 … … 1264 1622 function remove_brand($id=NULL) { 1265 1623 $brand_dir =& $this->db->getOne("SELECT directory FROM endpointman_brand_list WHERE id=".$id); 1624 $this->rmrf(PHONE_MODULES_PATH."endpoint/".$brand_dir); 1266 1625 1267 1626 $sql = "DELETE FROM endpointman_model_list WHERE brand = '". $id."'"; … … 1285 1644 * @return boolean True on sync completed. False on sync failed 1286 1645 */ 1287 function sync_model($model =NULL) {1646 function sync_model($model) { 1288 1647 1289 1648 //TODO: combine these queries … … 1320 1679 } 1321 1680 1322 $sql = "UPDATE endpointman_model_list SET template_list = '".$template_list."' WHERE id = '".$model."'";1681 $sql = "UPDATE endpointman_model_list SET max_lines = '".$family_line_xml['data']['model_list'][$key[0]]['lines']."', template_list = '".$template_list."' WHERE id = '".$model."'"; 1323 1682 $this->db->query($sql); 1324 1683 … … 1335 1694 if(file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data)) { 1336 1695 $template_data_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data); 1337 $template_data_xml = $this->fix_single_array_keys($template_data_xml['template_data'] ['item']);1696 $template_data_xml = $this->fix_single_array_keys($template_data_xml['template_data']); 1338 1697 $template_data_array = array_merge($template_data_array, $template_data_xml); 1339 1698 } … … 1532 1891 1533 1892 /** 1534 * A function to quickly remove a directory (works in seconds for a hundred thousand files) 1535 * @author http://www.php.net/manual/en/function.glob.php#93669 1893 * The RecursiveIteratorIterator must be told to provide children (files and subdirectories) before parents with its CHILD_FIRST constant. 1894 * Using RecursiveIteratorIterator is the only way PHP is able to see hidden files. 1895 * @author http://www.webcheatsheet.com/PHP/working_with_directories.php 1536 1896 * @param string $dir Full Directory path to delete 1537 1897 */ 1538 1898 function rmrf($dir) { 1539 foreach (glob($dir) as $file) { 1540 if (is_dir($file)) { 1541 $this->rmrf("$file/*"); 1542 rmdir($file); 1543 } else { 1544 unlink($file); 1545 } 1899 if(file_exists($dir)) { 1900 $iterator = new RecursiveDirectoryIterator($dir); 1901 foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { 1902 if ($file->isDir()) { 1903 @rmdir($file->getPathname()); 1904 } else { 1905 @unlink($file->getPathname()); 1906 } 1907 } 1908 //Remove parent path as the last step 1909 @rmdir($dir); 1546 1910 } 1547 1911 } … … 1697 2061 //It might be better to use switch here instead of these IF statements... 1698 2062 1699 //Is the mac separated by colons(:) ?2063 //Is the mac separated by colons(:) or dashes(-)? 1700 2064 if (preg_match("/[0-9a-f][0-9a-f][:-]". 1701 2065 "[0-9a-f][0-9a-f][:-]". … … 1704 2068 "[0-9a-f][0-9a-f][:-]". 1705 2069 "[0-9a-f][0-9a-f]/i", $mac)) { 1706 return(strtoupper(str_replace(":", "", $mac)));2070 return(strtoupper(str_replace(":", "", str_replace("-", "", $mac)))); 1707 2071 //Is the string exactly 12 characters? 1708 2072 } elseif(strlen($mac) == "12") { … … 1785 2149 1786 2150 //Go through each row of valid arp entries and pull out the information and add it into a nice array! 2151 $z = 0; 1787 2152 foreach ($temp as $key => &$value) { 1788 2153 … … 1831 2196 1832 2197 //Add into a final array 1833 $final[$key] = array("ip" => $ip, "mac" => $mac, "mac_strip" => $mac_strip, "oui" => $oui, "brand" => $brand['name'], "brand_id" => $brand['id'], "endpoint_managed" => $epm); 1834 } 1835 } 1836 1837 $final = array_values($final); 2198 $final[$z] = array("ip" => $ip, "mac" => $mac, "mac_strip" => $mac_strip, "oui" => $oui, "brand" => $brand['name'], "brand_id" => $brand['id'], "endpoint_managed" => $epm); 2199 $z++; 2200 } 2201 } 2202 2203 //$final = array_values($final); 1838 2204 1839 2205 if(!is_array($final)) { … … 1845 2211 1846 2212 function areaAvailable($model,$area=NULL) { 1847 1848 $temp[0]['value'] = 'GLOBAL';1849 $temp[0]['text'] = 'GLOBAL';1850 $temp[0]['selected'] = 0;1851 1852 $temp[1]['value'] = 'ALL';1853 $temp[1]['text'] = 'ALL LINES';1854 $temp[1]['selected'] = 0;1855 1856 2213 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = '". $model."'"; 1857 1858 2214 $count = $this->db->getOne($sql); 2215 2216 //TODO: FIX this 2217 /** 2218 if($count == 0) { 2219 $this->sync_model($model); 2220 $sql = "SELECT max_lines FROM endpointman_model_list WHERE id = '". $model."'"; 2221 $count = $this->db->getOne($sql); 2222 if($count == 0) { 2223 die("Can't Reset Lines to more than 0! ['areaAvailble']"); 2224 } 2225 } 2226 * 2227 */ 1859 2228 for($z=0;$z<$count;$z++) { 1860 2229 $result[$z]['id'] = $z + 1; … … 1862 2231 } 1863 2232 1864 $i = 2;2233 $i = 1; 1865 2234 foreach($result as $row) { 1866 if ($row['id'] == $ model) {2235 if ($row['id'] == $area) { 1867 2236 $temp[$i]['value'] = $row['id']; 1868 $temp[$i]['text'] = 'Line '.$row['model'];2237 $temp[$i]['text'] = $row['model']; 1869 2238 $temp[$i]['selected'] = 'selected'; 1870 2239 }else { 1871 2240 $temp[$i]['value'] = $row['id']; 1872 $temp[$i]['text'] = 'Line '.$row['model'];2241 $temp[$i]['text'] = $row['model']; 1873 2242 $temp[$i]['selected'] = 0; 1874 2243 } … … 1879 2248 } 1880 2249 1881 function modelsAvailable($model=NULL, $macAdd=NULL, $brand=NULL, $product=NULL) { 1882 if (isset($macAdd)) { 1883 $oui=substr($macAdd,0,6); 1884 } 2250 /** 2251 * 2252 * @param integer $model model ID 2253 * @param integer $brand brand ID 2254 * @param integer $product product ID 2255 * @return array 2256 */ 2257 function models_available($model=NULL, $brand=NULL, $product=NULL) { 2258 1885 2259 if ((!isset($oui)) && (!isset($brand)) && (!isset($model))) { 1886 $ sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.hidden = 0";2260 $result1 =& $this->endpoint_data->all_models(); 1887 2261 }elseif((isset($brand)) && ($brand !=0)) { 1888 $ sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.hidden = 0 AND endpointman_model_list.brand = " . $brand;2262 $result1 =& $this->endpoint_data->all_models_by_brand($brand); 1889 2263 }elseif((isset($product)) && ($product !=0)) { 1890 $sql="SELECT * FROM endpointman_model_list WHERE product_id = ".$product; 1891 } else { 1892 $sql="SELECT endpointman_model_list.* FROM endpointman_model_list, endpointman_product_list WHERE endpointman_model_list.product_id = endpointman_product_list.id AND endpointman_model_list.enabled = 1 AND endpointman_product_list.hidden = 0"; 1893 } 1894 1895 1896 $result1 =& $this->db->getAll($sql, array(),DB_FETCHMODE_ASSOC); 2264 $result1 =& $this->endpoint_data->all_models_by_product($product); 2265 } else { 2266 $result1 =& $this->endpoint_data->all_models(); 2267 } 1897 2268 1898 2269 $i = 1; … … 1918 2289 } 1919 2290 1920 function linesAvailable($model=NULL, $macid=NULL) { 1921 1922 if(isset($model)) { 1923 $sql="SELECT `max_lines` FROM `endpointman_model_list` WHERE `id` LIKE"; 1924 } 1925 1926 1927 $result1 =& $this->db->getAll($sql, array(),DB_FETCHMODE_ASSOC); 1928 1929 $i = 1; 1930 foreach($result1 as $row) { 1931 if ($row['id'] == $model) { 1932 $temp[$i]['value'] = $row['id']; 1933 $temp[$i]['text'] = $row['model']; 1934 $temp[$i]['selected'] = 'selected'; 1935 }else { 1936 $temp[$i]['value'] = $row['id']; 1937 $temp[$i]['text'] = $row['model']; 1938 $temp[$i]['selected'] = 0; 1939 } 1940 $i++; 1941 } 1942 1943 if(!isset($temp)) { 1944 $this->error['modelsAvailable'] = "You need to enable at least ONE model"; 1945 return(FALSE); 1946 } else { 2291 function in_array_recursive($needle, $haystack) { 2292 2293 $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($haystack)); 2294 2295 foreach($it AS $element) { 2296 if($element == $needle) { 2297 return TRUE; 2298 } 2299 } 2300 return FALSE; 2301 } 2302 2303 function linesAvailable($lineid=NULL,$macid=NULL) { 2304 if(isset($lineid)) { 2305 $sql="SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT endpointman_mac_list.model FROM endpointman_mac_list, endpointman_line_list WHERE endpointman_line_list.luid = ".$lineid." AND endpointman_line_list.mac_id = endpointman_mac_list.id)"; 2306 2307 $sql_l = "SELECT line, mac_id FROM `endpointman_line_list` WHERE luid = ".$lineid; 2308 $line =& $this->db->getRow($sql_l, array(), DB_FETCHMODE_ASSOC); 2309 2310 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = ".$line['mac_id']; 2311 } elseif(isset($macid)) { 2312 $sql="SELECT max_lines FROM endpointman_model_list WHERE id = (SELECT model FROM endpointman_mac_list WHERE id =".$macid.")"; 2313 $sql_lu = "SELECT line FROM endpointman_line_list WHERE mac_id = ".$macid; 2314 2315 $line['line'] = 0; 2316 } 2317 2318 $max_lines = $this->db->getOne($sql); 2319 $lines_used =& $this->db->getAll($sql_lu); 2320 2321 for($i = 1; $i <= $max_lines; $i++) { 2322 if($i == $line['line']) { 2323 $temp[$i]['value'] = $i; 2324 $temp[$i]['text'] = $i; 2325 $temp[$i]['selected'] = "selected"; 2326 } else { 2327 if(!$this->in_array_recursive($i,$lines_used)) { 2328 $temp[$i]['value'] = $i; 2329 $temp[$i]['text'] = $i; 2330 } 2331 } 2332 } 2333 if(isset($temp)) { 1947 2334 return($temp); 1948 } 1949 } 1950 1951 function displayExtension($line_id = NULL) { 1952 if(!isset($line_id)) { 1953 $ext = NULL; 1954 $not_added="SELECT devices.id, devices.description FROM devices WHERE tech='sip' AND devices.id not in (SELECT devices.id FROM devices, endpointman_line_list WHERE tech='sip' AND devices.id = endpointman_line_list.ext ) ORDER BY devices.id"; 1955 } else { 1956 $sql = 'SELECT ext FROM endpointman_line_list WHERE luid = '.$line_id; 1957 $ext = $this->db->getOne($sql); 1958 $not_added="SELECT devices.id, devices.description FROM devices WHERE tech='sip' AND devices.id not in (SELECT devices.id FROM devices, endpointman_line_list WHERE tech='sip' AND devices.id = endpointman_line_list.ext AND endpointman_line_list.ext !=".$ext." ) ORDER BY devices.id"; 1959 } 1960 $result =& $this->db->getAll($not_added,array(), DB_FETCHMODE_ASSOC); 1961 2335 } else { 2336 return FALSE; 2337 } 2338 } 2339 2340 /** 2341 * Display all unused registrations from whatever manager we are using! 2342 * @return <type> 2343 */ 2344 function display_registration_list($line_id=NULL) { 2345 2346 if(isset($line_id)) { 2347 $result =& $this->endpoint_data->all_unused_registrations(); 2348 $line_data =& $this->endpoint_data->get_line_information($line_id); 2349 } else { 2350 $result =& $this->endpoint_data->all_unused_registrations(); 2351 $line_data = NULL; 2352 } 1962 2353 1963 2354 $i = 1; … … 1966 2357 $temp[$i]['value'] = $row['id']; 1967 2358 $temp[$i]['text'] = $row['id'] . " --- " . $row['description']; 1968 if ($row['id'] == $ext) {1969 $temp[$i]['selected'] = "selected";1970 }1971 2359 $i++; 2360 } 2361 2362 if(isset($line_data)) { 2363 $temp[$i]['value'] = $line_data['ext']; 2364 $temp[$i]['text'] = $line_data['ext'] . " --- " . $line_data['description']; 2365 $temp[$i]['selected'] = "selected"; 1972 2366 } 1973 2367 … … 1980 2374 * @return array Number array used to generate a select box 1981 2375 */ 1982 function brandAvailable ($selected = NULL) { 1983 $sql="SELECT DISTINCT endpointman_brand_list.name, endpointman_brand_list.id FROM endpointman_brand_list,endpointman_model_list WHERE endpointman_model_list.brand = endpointman_brand_list.id AND endpointman_model_list.enabled = 1 AND endpointman_model_list.hidden = 0 AND endpointman_brand_list.installed = 1 AND endpointman_brand_list.hidden = 0"; 1984 1985 $data =& $this->db->getAll($sql,array(), DB_FETCHMODE_ASSOC); 1986 $temp[0]['value'] = ""; 1987 $temp[0]['text'] = ""; 1988 $i = 1; 2376 function brands_available ($selected = NULL,$show_blank=TRUE) { 2377 $data =& $this->endpoint_data->all_active_brands(); 2378 if($show_blank) { 2379 $temp[0]['value'] = ""; 2380 $temp[0]['text'] = ""; 2381 $i = 1; 2382 } else { 2383 $i = 0; 2384 } 1989 2385 foreach($data as $row) { 1990 2386 $temp[$i]['value'] = $row['id']; modules/branches/2.9/endpointman/includes/installer.php
r10233 r10792 18 18 19 19 if($_REQUEST['type'] == "brand") { 20 $endpoint-> update_brand($_REQUEST['id']);20 $endpoint->download_brand($_REQUEST['id']); 21 21 } elseif($_REQUEST['type'] == "js-multiple") { 22 22 $list = explode(",",$_REQUEST['id']); … … 72 72 if ((file_exists(PHONE_MODULES_PATH."temp/".$_REQUEST['package'])) AND (file_exists(PHONE_MODULES_PATH."temp/".$_REQUEST['xml']))) { 73 73 $temp = $endpoint->xml2array(PHONE_MODULES_PATH."temp/".$_REQUEST['xml']); 74 75 $brand_name = $temp['data']['brands']['name']; 76 $brand_id = $temp['data']['brands']['brand_id']; 77 $brand_version = $temp['data']['brands']['version']; 78 $package = $temp['data']['brands']['package']; 79 $brand_directory = $temp['data']['brands']['directory']; 80 81 if(!file_exists(PHONE_MODULES_PATH."endpoint/".$brand_directory)) { 82 echo "Creating ".$brand_name." Directory <br />"; 83 mkdir(PHONE_MODULES_PATH."endpoint/".$brand_directory); 84 } 85 86 rename(PHONE_MODULES_PATH."temp/".$_REQUEST['xml'], PHONE_MODULES_PATH."endpoint/".$brand_directory."/brand_data.xml"); 87 88 echo "Extracting Tarball........"; 89 exec("tar -xvf ".PHONE_MODULES_PATH.'temp/'. $package ." -C ".PHONE_MODULES_PATH."temp/"); 90 echo "Done!<br />"; 91 92 echo "Creating Directory Structure/Moving Files..............."; 93 $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."temp/".$brand_directory."/"); 94 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); 95 // could use CHILD_FIRST if you so wish 96 97 foreach ($iterator as $file) { 98 if(is_dir($file)) { 99 $dir = str_replace(PHONE_MODULES_PATH."temp/".$brand_directory."/", "", $file); 100 if(!file_exists(PHONE_MODULES_PATH."endpoint/".$brand_directory."/".$dir)) { 101 mkdir(PHONE_MODULES_PATH."endpoint/".$brand_directory."/".$dir); 102 } 103 } else { 104 if(basename($file) != "brand_data.xml") { 105 $dir = str_replace(PHONE_MODULES_PATH."temp/".$brand_directory."/", "", $file); 106 rename($file, PHONE_MODULES_PATH."endpoint/".$brand_directory."/".$dir); 107 } 108 } 109 } 110 echo "Done!<br />"; 111 echo "Removing Temporary Files.............."; 112 $endpoint->deltree(PHONE_MODULES_PATH."temp/" .$brand_directory); 113 unlink(PHONE_MODULES_PATH.'temp/'. $_REQUEST['package']); 114 echo "Done!<br />"; 115 116 $last_mod = ""; 117 $temp['data']['brands']['family_list']['family'] = $endpoint->fix_single_array_keys($temp['data']['brands']['family_list']['family']); 118 foreach($temp['data']['brands']['family_list']['family'] as $family_list) { 119 echo "Updating Family Lines.................<br/>"; 120 $last_mod = max($last_mod, $family_list['last_modified']); 121 122 $family_line_xml = $endpoint->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_directory.'/'.$family_list['directory'].'/family_data.xml'); 123 $data =& $endpoint->db->getOne("SELECT id FROM endpointman_product_list WHERE id='".$brand_id.$family_line_xml['data']['id']."'", array(), DB_FETCHMODE_ASSOC); 124 $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); 125 if($data) { 126 $sql = "UPDATE endpointman_product_list SET short_name = '".$short_name."', long_name = '".$family_line_xml['data']['name']."', cfg_ver = '".$family_line_xml['data']['version']."', config_files='".$family_line_xml['data']['configuration_files']."', hidden = '0' WHERE id = '".$brand_id.$family_line_xml['data']['id']."'"; 127 } else { 128 $sql = "INSERT INTO endpointman_product_list (`id`, `brand`, `short_name`, `long_name`, `cfg_dir`, `cfg_ver`, `config_files`, `hidden`) VALUES ('".$brand_id.$family_line_xml['data']['id']."', '".$brand_id."', '".$short_name."', '".$family_line_xml['data']['name']."', '".$family_line_xml['data']['directory']."', '".$family_line_xml['data']['version']."','".$family_line_xml['data']['configuration_files']."', '0')"; 129 } 130 131 $endpoint->db->query($sql); 132 $family_line_xml['data']['model_list'] = $endpoint->fix_single_array_keys($family_line_xml['data']['model_list']); 133 echo "--Updating Model Lines................<br/>"; 134 foreach($family_line_xml['data']['model_list'] as $model_list) { 135 if(is_array($model_list['template_data']['files'])) { 136 $template_list = implode(",",$model_list['template_data']['files']); 137 } else { 138 $template_list = $model_list['template_data']['files']; 139 } 140 $m_data =& $endpoint->db->getOne("SELECT id FROM endpointman_model_list WHERE id='".$brand_id.$family_line_xml['data']['id'].$model_list['id']."'", array(), DB_FETCHMODE_ASSOC); 141 if($m_data) { 142 $sql = "UPDATE endpointman_model_list SET model = '".$model_list['model']."', template_list = '".$template_list."', enabled = '0', hidden = '0' WHERE id = '".$brand_id.$family_line_xml['data']['id']."'"; 143 } else { 144 $sql = "INSERT INTO endpointman_model_list (`id`, `brand`, `model`, `product_id`, `template_list`, `enabled`, `hidden`) VALUES ('".$brand_id.$family_line_xml['data']['id'].$model_list['id']."', '".$brand_id."', '".$model_list['model']."', '".$brand_id.$family_line_xml['data']['id']."', '".$template_list."', '0', '0')"; 145 } 146 $endpoint->db->query($sql); 147 } 148 } 149 150 $row =& $endpoint->db->getAll('SELECT * FROM endpointman_brand_list WHERE id > 0', array(), DB_FETCHMODE_ASSOC); 151 152 153 if(file_exists(PHONE_MODULES_PATH."endpoint/".$brand_directory."/brand_data.xml")) { 154 $temp = $endpoint->xml2array(PHONE_MODULES_PATH."endpoint/".$brand_directory."/brand_data.xml"); 155 156 $temp = $temp['data']['brands']; 157 158 $temp['oui_list']['oui'] = $endpoint->fix_single_array_keys($temp['oui_list']['oui']); 159 160 foreach($temp['oui_list']['oui'] as $oui) { 161 $sql = "INSERT INTO endpointman_oui_list (`oui`, `brand`, `custom`) VALUES ('".$oui."', '".$temp['brand_id']."', '0')"; 162 $endpoint->db->query($sql); 163 164 } 165 166 $brand_name = $temp['directory']; 167 $version[$brand_name] = $temp['last_modified']; 168 169 $last_mod = ""; 170 171 $temp['family_list']['family'] = $endpoint->fix_single_array_keys($temp['family_list']['family']); 172 173 foreach($temp['family_list']['family'] as $list) { 174 $last_mod = max($last_mod, $list['last_modified']); 175 } 176 $last_mod = max($last_mod, $version[$brand_name]); 177 178 $version[$brand_name] = $last_mod; 179 180 if(!($endpoint->arraysearchrecursive($brand_name, $row, 'directory'))) { 181 //insert row 182 $sql = "INSERT INTO endpointman_brand_list (id, name, directory, cfg_ver, installed) VALUES ('".$temp['brand_id']."', '".$temp['name']."', '".$temp['directory']."', '".$version[$brand_name]."', 1)"; 183 $endpoint->db->query($sql); 184 } else { 185 $brand_version = max($last_mod, $brand_version); 186 echo "Updating data.........."; 187 $sql = "UPDATE endpointman_brand_list SET name = '".$temp['name']."', cfg_ver = '".$version[$brand_name]."', installed = 1, hidden = 0 WHERE id = ".$temp['brand_id']; 188 $endpoint->db->query($sql); 189 echo "Done!<br/>"; 190 } 191 } 74 $endpoint->update_brand($temp); 192 75 } 193 76 break; modules/branches/2.9/endpointman/includes/rain.tpl.class.php
r9907 r10792 5 5 * Project: RainTPL, compile HTML template to PHP. 6 6 * 7 * File: rain tpl.class.php7 * File: rain.tpl.class.php 8 8 * 9 9 * This library is free software; you can redistribute it and/or … … 22 22 * 23 23 * @link http://www.raintpl.com 24 * @author Federico Ulfo < info@rainelemental.net>25 * @version 1. 7.526 * @copyright 2006 - 20 09 Federico Ulfo | www.RainElemental.net27 * @package Rain TPL24 * @author Federico Ulfo <rainelemental@gmail.com> 25 * @version 1.9.1 26 * @copyright 2006 - 2010 Federico Ulfo | www.federicoulfo.it 27 * @package Rain 28 28 */ 29 29 … … 41 41 42 42 43 43 44 /** 44 45 * Extension of template … … 50 51 51 52 52 /** 53 * Questa costante serve per la sicurezza dei template, in modo che un template non pu˜ essere eseguito senza questa classe. 54 * 55 */ 56 53 // DO NOT CHANGE!!! In each compiled template there's a check that this constant is declared, to deny the direct execution of compiled template 57 54 define( "IN_RAINTPL", true ); 58 55 … … 61 58 /** 62 59 * RainTPL Template class. 63 * Questa classe permette di caricare e visualizzare i template60 * Load and draw templates 64 61 * 65 62 * @access public … … 70 67 71 68 /** 72 * Contiene tutte le variabili assegnate al template69 * All templates variables 73 70 * @access private 74 71 * @var array … … 78 75 79 76 /** 80 * Directory dove sono i templates77 * Template directory 81 78 * @access private 82 79 * @var string 83 80 */ 84 var $tpl_dir = "themes/"; 81 static $tpl_dir = "tpl", 82 $tpl_compile_dir = "tmp/", 83 $base_dir = null; 85 84 86 85 87 86 88 87 /** 89 * Inizializza la classe.88 * Constructor 90 89 * 91 * @param string $tpl_dir Setta la directory da cui prendere i template. E' sufficente settarla al primo utilizzo del template engine90 * @param string $tpl_dir Template directory. It must be set the first time you use the class 92 91 * @return RainTPL 93 92 */ 94 93 95 function RainTPL( $tpl_dir = null ){ 96 94 function RainTPL( $tpl_dir = null, $tpl_compile_dir = null, $base_dir = null ){ 97 95 if( $tpl_dir ) 98 $this->tpl_dir = $GLOBALS[ 'RainTPL_tpl_dir' ] = $tpl_dir . ( substr($tpl_dir,-1,1) != "/" ? "/" : "" ); 99 elseif( isset( $GLOBALS[ 'RainTPL_tpl_dir' ] ) ) 100 $this->tpl_dir = $GLOBALS[ 'RainTPL_tpl_dir' ]; 101 96 RainTPL::$tpl_dir = $tpl_dir . ( substr($tpl_dir,-1,1) != "/" ? "/" : "" ); 97 if( $tpl_compile_dir ) 98 RainTPL::$tpl_compile_dir = $tpl_compile_dir; 99 if( $base_dir ) 100 RainTPL::$base_dir = $base_dir; 102 101 } 103 102 … … 137 136 * echo $tpl->draw( $tpl_name, TRUE ); 138 137 * 139 * @param string $tpl_name Nome del template da caricare138 * @param string $tpl_name template to load 140 139 * @return string 141 140 */ … … 151 150 $tpl_dir = null; 152 151 153 //var is the variabile che si trova in ognitemplate152 //var of all template 154 153 $var = $this->variables; 155 154 156 if( !file_exists( $template_file = $this->tpl_dir . $tpl_dir . $tpl_name . '.' . TPL_EXT ) ){155 if( !file_exists( $template_file = RainTPL::$tpl_dir . $tpl_dir . $tpl_name . '.' . TPL_EXT ) ){ 157 156 trigger_error( "Template not found: $tpl_name" ); 158 157 if( $return_string ) … … 163 162 } 164 163 } 165 elseif( !is_writable( $this->tpl_dir) )166 $compiled_filename = $this->tpl_dir . $tpl_dir . "/compiled/" . $tpl_name . "_def.php";167 elseif( TPL_CACHE_ENABLED && file_exists( $this->tpl_dir . $tpl_dir . "/compiled/". $tpl_name . "_" . ( $filetime = filemtime( $template_file ) ) . ".php" ) )168 $compiled_filename = $this->tpl_dir . $tpl_dir . "/compiled/". $tpl_name . "_" . $filetime . ".php";164 elseif( is_dir( RainTPL::$tpl_compile_dir . RainTPL::$tpl_dir ) && !is_writable( RainTPL::$tpl_compile_dir."/" ) ) 165 $compiled_filename = RainTPL::$tpl_compile_dir."/" . $tpl_dir . $tpl_name . ".php"; 166 elseif( TPL_CACHE_ENABLED && file_exists( RainTPL::$tpl_compile_dir."/" . $tpl_dir . $tpl_name . "_" . ( $filetime = filemtime( $template_file ) ) . ".php" ) ) 167 $compiled_filename = RainTPL::$tpl_compile_dir."/" . $tpl_dir . $tpl_name . "_" . $filetime . ".php"; 169 168 else{ 170 169 include_once "rain.tpl.compile.class.php"; 171 170 $RainTPLCompile_obj = new RainTPLCompile( ); 172 $RainTPLCompile_obj->compileFile( $tpl_name, $this->tpl_dir . $tpl_dir );171 $RainTPLCompile_obj->compileFile( $tpl_name, RainTPL::$tpl_dir . $tpl_dir, RainTPL::$tpl_compile_dir."/", RainTPL::$base_dir ); 173 172 // template last update date 174 $filetime = filemtime( $this->tpl_dir . $tpl_dir . '/' . $tpl_name . '.' . TPL_EXT );175 $compiled_filename = $this->tpl_dir . $tpl_dir . "/compiled/". $tpl_name . "_" . $filetime . ".php";176 } 173 $filetime = filemtime( RainTPL::$tpl_dir . $tpl_dir . '/' . $tpl_name . '.' . TPL_EXT ); 174 $compiled_filename = RainTPL::$tpl_compile_dir."/". $tpl_dir . $tpl_name . "_" . $filetime . ".php"; 175 } 177 176 178 177 179 180 181 178 //if return_string is true, the function return the output as a string 182 179 if( $return_string ){ … … 191 188 192 189 } 193 194 190 195 191 } modules/branches/2.9/endpointman/includes/rain.tpl.compile.class.php
r9907 r10792 5 5 * Project: RainTPL, compile HTML template to PHP 6 6 * 7 * File: rain tpl.compile.class.php7 * File: rain.tpl.compile.class.php 8 8 * 9 9 * This library is free software; you can redistribute it and/or … … 22 22 * 23 23 * @link http://www.raintpl.com 24 * @author Federico Ulfo < info@rainelemental.net>25 * @version 1. 7.526 * @copyright 2006 - 20 08 Federico Ulfo | www.RainElemental.net27 * @package Rain TPL24 * @author Federico Ulfo <rainelemental@gmail.com> 25 * @version 1.9.1 26 * @copyright 2006 - 2010 Federico Ulfo | www.federicoulfo.it 27 * @package Rain 28 28 */ 29 29 … … 42 42 43 43 44 45 44 /** 46 * 47 *Cache enabled: 48 * TRUE improve speed 49 * FALSE recompile template each executions 50 * 45 * Rain TPL version 51 46 */ 52 47 53 define( "RAINTPL_VERSION", '1.7.5' ); 48 define( "RAINTPL_VERSION", '1.9.1' ); 49 50 51 54 52 55 53 … … 64 62 class RainTPLCompile{ 65 63 66 /**67 * Template directory, default: themes68 * @access private69 * @var string70 */71 var $tpl_dir = "themes";72 73 64 74 65 /** … … 81 72 82 73 /** 83 * Regular expression pattern 84 * @access private 85 * @var string 86 */ 87 var $show_copyright = true; 88 74 * Template dir 75 */ 76 var $tpl_dir = null; 77 78 79 /** 80 * Base directory of path substitution 81 */ 82 var $base_dir = null; 89 83 90 84 … … 93 87 * 94 88 * @access private 95 * @param string $template_name 96 * @param string $template_directory 97 */ 98 99 function compileFile( $template_name, $template_directory ){ 100 101 //set the temlate directory 102 $this->tpl_dir = $template_directory; 103 104 //if directory $this->tpl_dir/compiled doesn't exist, create its and compile all file into $this->tpl_dir 105 if( !file_exists( $this->tpl_dir . '/compiled/' ) ) 106 mkdir( $this->tpl_dir . '/compiled/', 0755 ); 107 108 if( $compiled_file = glob( $this->tpl_dir . '/compiled/' . $template_name . '*.php' ) ) 109 foreach( $compiled_file as $file_name ) 89 * @param string $tpl_name 90 * @param string $tpl_dir 91 */ 92 93 function compileFile( $tpl_name, $tpl_dir, $tpl_compile_dir = null, $base_dir = null ){ 94 $this->tpl_dir = $tpl_dir; 95 $this->base_dir = $base_dir; 96 97 // delete all the file with similar name 98 if( $compiled_files = glob( $tpl_compile_dir . $tpl_name . '*.php' ) ) 99 foreach( $compiled_files as $file_name ) 110 100 unlink( $file_name ); 111 101 112 //leggo il template 113 $template_code = file_get_contents( $this->tpl_dir . '/' . $template_name . '.' . TPL_EXT ); 114 115 116 //sostituzione per xml 102 //read template file 103 $template_code = file_get_contents( $tpl_dir . $tpl_name . '.' . TPL_EXT ); 104 105 //xml substitution 117 106 $template_code = preg_replace( "/\<\?xml(.*?)\?\>/", "##XML\\1XML##", $template_code ); 118 119 //se i tag php sono disabilitati nei template 120 if( !RAINTPL_PHP_ENABLED ){ 121 $template_code = str_replace( "<?", "<?", $template_code ); 122 $template_code = str_replace( "?>", "?>", $template_code ); 107 108 //if tag are disabled 109 if( !RAINTPL_PHP_ENABLED ) 110 $template_code = str_replace( array("<?","?>"), array("<?","?>"), $template_code ); 111 112 //xml substitution 113 $template_code = preg_replace( "/\#\#XML(.*?)XML\#\#/", "<?php echo '<?xml' . stripslashes('\\1') . '?>'; ?>", $template_code ); 114 115 //compile template 116 $template_compiled = $this->compileTemplate( $template_code, $tpl_name ); 117 $template_compiled = "<?php if(!defined('IN_RAINTPL')){exit('Hacker attempt');}?>" . $template_compiled; 118 119 //write compiled file 120 $filename = $tpl_compile_dir . $tpl_name . "_" . filemtime( $tpl_dir . '/' . $tpl_name . '.' . TPL_EXT ) . ".php"; 121 122 $dir = explode( "/", $tpl_compile_dir ); 123 for( $i=0, $base=""; $i<count($dir);$i++ ){ 124 $base .= $dir[$i] . "/"; 125 if( !is_dir($base) ) 126 mkdir( $base ); 123 127 } 124 125 //sostituzione per xml 126 $template_code = preg_replace( "/\#\#XML(.*?)XML\#\#/", "<?php echo '<?xml\\1?>'; ?>", $template_code ); 127 128 129 //compilo il template 130 131 $template_compiled = $this->compileTemplate( $template_code, $template_name ); 132 $template_compiled = "<?php if(!defined('IN_RAINTPL')){exit('Hacker attempt');}?>" . $template_compiled; 133 134 //scrivo il file compilato 135 fwrite( $fp = fopen( $this->tpl_dir . "/compiled/" . $template_name . "_" . filemtime( $this->tpl_dir . '/' . $template_name . '.' . TPL_EXT ) . ".php", 'w' ), $template_compiled ); 136 137 //chiudo l'handler del file 138 fclose( $fp ); 139 128 129 file_put_contents( $filename, $template_compiled ); 130 131 140 132 } 141 133 … … 148 140 * @param string 149 141 */ 150 function compileTemplate( $template_code, $t emplate_name ){151 152 // divido il codice del template nei vari tag142 function compileTemplate( $template_code, $tpl_name ){ 143 144 //get all the tags into the template 153 145 $template_code = preg_split ( $this->split_pattern, $template_code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 154 146 155 // compilo il codice parsato in codice php147 //get the compiled code 156 148 $compiled_code = $this->compileCode( $template_code ); 157 149 158 if( !$this->show_copyright ) 159 return $compiled_code; 160 else 161 //creo il codice da inserire nel template 162 return "<!-- $template_name | generated by RainTPL v " . RAINTPL_VERSION . " | www.RainTPL.com -->" . "\n" . 163 $compiled_code . "\n" . 164 "<!--/ $template_name -->" . "\n"; 165 166 167 150 return $compiled_code; 151 168 152 } 169 153 170 154 /** 171 * Compil o il codice parsato in php155 * Compile the code 172 156 * 173 157 * @access private 174 * @param string $parsed_code Array che contiene codice html etag175 * @return string co dice compilato158 * @param string $parsed_code Array that contain html and tag 159 * @return string compiled code 176 160 */ 177 161 function compileCode( $parsed_code ){ 178 162 179 // inizializzo tutte le variabili163 //variables initialization 180 164 $parent_loop[ $level = 0 ] = $loop_name = $compiled_code = $compiled_return_code = null; 181 165 $open_if = $comment_is_open = $ignore_is_open = 0; 182 166 183 // leggo tutti gli elementi dell'array del codice parsato167 //read all parsed code 184 168 while( $html = array_shift( $parsed_code ) ){ 185 169 186 // calcolo lo spazio per l'indentazione del codice compilato170 //indentation 187 171 for( $space_counter = 0, $space = ""; $space_counter < $level + $open_if; $space_counter++, $space .= " " ); 188 172 189 // Chiudo il tag ignore173 //close ignore tag 190 174 if( !$comment_is_open && preg_match( '/\{\/ignore\}/', $html ) ) 191 175 $ignore_is_open = false; 192 176 193 // tutto il codice tra il tag ignore ed /ignore viene cancellato177 //code between tag ignore id deleted 194 178 elseif( $ignore_is_open ){ 195 179 //non faccio niente 196 180 } 197 198 // Chiudo il tag noparse181 182 //close no parse tag 199 183 elseif( preg_match( '/\{\/noparse\}/', $html ) ) 200 184 $comment_is_open = false; 201 185 202 // tutto il codice tra il tag noparse e /noparse non viene compilato186 //code between tag noparse is not compiled 203 187 elseif( $comment_is_open ){ 204 188 $compiled_code .= $html; 205 189 } 206 190 207 // Apro il tagignore191 //ignore 208 192 elseif( preg_match( '/\{ignore\}/', $html ) ) 209 193 $ignore_is_open = true; 210 194 211 // apro il tagnoparse195 //noparse 212 196 elseif( preg_match( '/\{noparse\}/', $html ) ) 213 197 $comment_is_open = true; 214 198 215 //in serisco il comando include199 //include tag 216 200 elseif( preg_match( '/(?:\{include="(.*?)"\})/', $html, $code ) ){ 217 201 218 // sostituisco le variabili che si trovano nel tag include202 //variables substitution 219 203 $include_var = $this->var_replace( $code[ 1 ], $left_delimiter = null, $right_delimiter = null, $php_left_delimiter = '".' , $php_right_delimiter = '."', $this_loop_name = $parent_loop[ $level ] ); 220 221 // inserisco il codice php per includere il file dinamicamente con il RainTPL204 205 //dynamic include 222 206 $compiled_code .= "<?php\n" . 223 "\$RainTPL_include_obj = new RainTPL();\n" . 224 "\$RainTPL_include_obj->assign( \$var );\n" . 225 "\$RainTPL_directory_template_temp = \$RainTPL_include_obj->tpl_dir;" . "\n" . 226 ( ( $this_loop_name ) ? "\$RainTPL_include_obj->assign( \"key\", \$key" . $this_loop_name . " );\n" . "\$RainTPL_include_obj->assign( \"value\", \$value" . $this_loop_name . " );\n" : null ) . 227 "\$this->tpl_dir = \$GLOBALS[ 'RainTPL_tpl_dir' ] = \$RainTPL_include_obj->tpl_dir . \"/\" . dirname( \"$include_var\" );" . "\n" . 228 "\$RainTPL_include_obj->draw( \"$include_var\" );" . "\n" . 229 "\$this->tpl_dir = \$GLOBALS[ 'RainTPL_tpl_dir' ] = \$RainTPL_directory_template_temp;" . "\n" . 207 $space . " \$tpl = new RainTPL( RainTPL::\$tpl_dir . dirname(\"{$include_var}\"));\n" . 208 $space . " \$tpl->assign( \$var );\n" . 209 $space . " " . ( !$this_loop_name ? null : "\$tpl->assign( \"key\", \$key{$this_loop_name} );\n" . "\$tpl->assign( \"value\", \$value{$this_loop_name} );\n" ) . 210 $space . " \$tpl->draw(basename(\"{$include_var}\"));" . "\n" . 230 211 "?>"; 231 232 233 212 } 234 213 235 // apro il tagloop214 //loop 236 215 elseif( preg_match( '/(?:\{loop(?:\s+)name="(.*?)"\})/', $html, $code ) ){ 237 216 238 //incre mento la variabile level, che tiene conto del numero di tag loop aperti217 //increase the loop counter 239 218 $level++; 240 219 241 // inserisco nell'array parent_loop il nome di questoloop220 //name of this loop 242 221 $parent_loop[ $level ] = $level; 243 222 244 223 $var = $this->var_replace( '$' . $code[ 1 ], "","", "","", $level-1 ); 245 224 246 // creo le variabili php per il loop247 $counter = "\$counter$level"; 248 $key = "\$key$level"; 249 $value = "\$value$level"; 250 251 // scrivo il codice per aprire il tag loop225 //loop variables 226 $counter = "\$counter$level"; // count iteration 227 $key = "\$key$level"; // key 228 $value = "\$value$level"; // value 229 230 //loop code 252 231 $compiled_code .= "<?php" . "\n" . 253 $space . " if( isset( $var ) ){" . "\n" .232 $space . " if( isset( $var ) && is_array( $var ) ){" . "\n" . 254 233 $space . " $counter = 0;" . "\n" . 255 234 $space . " foreach( $var as $key => $value ){ " . "\n" . … … 258 237 } 259 238 260 //c hiudo il tag loop239 //close loop tag 261 240 elseif( preg_match( '/\{\/loop\}/', $html ) ){ 262 // carico la variabile counter241 //iterator 263 242 $counter = "\$counter$level"; 264 243 265 //d iminuisco il livello del loop244 //decrease the loop counter 266 245 $level--; 267 246 268 // scrivo il codice per chiudere il tag loop247 //close loop code 269 248 $compiled_code .= "<?php" . "\n" . 270 249 $space . " $counter++;" . "\n" . … … 274 253 } 275 254 276 // apro il tagif255 //if 277 256 elseif( preg_match( '/(?:\{if(?:\s+)condition="(.*?)"\})/', $html, $code ) ){ 278 257 279 //incre mento open_if (serve per l'indentazione del codice)258 //increase open if counter (for intendation) 280 259 $open_if++; 281 260 282 // recupero l'attributo condition del tag if261 //condition attribute 283 262 $condition = $code[ 1 ]; 284 263 285 // sostituisco le variabili all'interno della condizione del tag if, le variabili nell'if vengono inserite senza i delimitatori264 //variable substitution into condition (no delimiter into the condition) 286 265 $parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = '', $tag_right_delimiter = '', $php_left_delimiter = null, $php_right_delimiter = null, $parent_loop[ $level ] ); 287 266 288 // scrivo il codice php del tag if267 //if code 289 268 $compiled_code .= "<?php" . "\n" . 290 269 $space . " if( $parsed_condition ){" . "\n" . … … 292 271 } 293 272 294 // apro il tagelseif273 //elseif 295 274 elseif( preg_match( '/(?:\{elseif(?:\s+)condition="(.*?)"\})/', $html, $code ) ){ 296 275 297 //incre mento open_if276 //increase open if counter (for intendation) 298 277 $open_if++; 299 278 300 // recupero l'attributo condition del tag elseif279 //condition attribute 301 280 $condition = $code[ 1 ]; 302 281 303 // sostituisco le variabili all'interno della condizione del tag elseif, le variabili nell'elseif vengono inserite senza i delimitatori282 //variable substitution into condition (no delimiter into the condition) 304 283 $parsed_condition = $this->var_replace( $condition, $tag_left_delimiter = '', $tag_right_delimiter = '', $php_left_delimiter = null, $php_right_delimiter = null, $parent_loop[ $level ] ); 305 284 306 // scrivo il codice php del tag elseif285 //elseif code 307 286 $compiled_code .= "<?php" . "\n" . 308 287 $space . "}" . "\n" . … … 311 290 } 312 291 313 // apro il tagelse292 //else 314 293 elseif( preg_match( '/\{else\}/', $html ) ){ 315 294 316 // scrivo il codice php del tag else295 //else code 317 296 $compiled_code .= "<?php" . "\n" . 318 297 $space . "}" . "\n" . … … 322 301 } 323 302 324 //c hido il tag if303 //close if tag 325 304 elseif( preg_match( '/\{\/if}/', $html ) ){ 326 305 327 //decre mento $open_if306 //decrease if counter 328 307 $open_if--; 329 308 330 // scrivo il codice php del tag /if309 // close if code 331 310 $compiled_code .= "<?php" . "\n" . 332 311 $space . "}" . "\n" . … … 335 314 } 336 315 337 // scrivo il codice html, cio?tutto il codice che non e incluso tra tag316 //all html code 338 317 else{ 339 318 340 // sostituisco i percorsi di immagini e collegamenti a fogli di stile341 //$html = $this->path_replace( $html );342 343 // eseguo la sostituzione delle variabili nel codice319 //path replace (src of img, background and href of link) 320 $html = $this->path_replace( $html ); 321 322 //variables substitution (es. {$title}) 344 323 $compiled_code .= $this->var_replace( $html, $left_delimiter = '\{', $right_delimiter = '\}', $php_left_delimiter = '<?php echo ', $php_right_delimiter = ';?>', $parent_loop[ $level ] ); 345 324 … … 347 326 } 348 327 349 //restituisco il codice compilato328 350 329 return $compiled_code; 351 330 } … … 354 333 355 334 /** 356 * Sostituisce il percorso dei fogli di stile, dell'src delle immagini e del tag background 357 * 335 * Path replace (src of img, background and href of link) 336 * url => template_dir/url 337 * url# => url 338 * http://url => http://url 339 * 358 340 * @param string $html 359 341 * @return string html sostituito 360 342 */ 361 343 function path_replace( $html ){ 362 363 // sostituisco i percorsi di img, link e background: 364 // url => template_dir/url 365 // url# => url# 366 // http://url => http://url 367 368 $exp = array( '/src=(?:")http\:\/\/([^"]+)(?:")/i', '/src=(?:")([^"]+)#(?:")/i', '/src="(.*?)"/', '/src=(?:\@)([^"]+)(?:\@)/i', '/background=(?:")http\:\/\/([^"]+)(?:")/i', '/background=(?:")([^"]+)#(?:")/i', '/background="(.*?)"/', '/background=(?:\@)([^"]+)(?:\@)/i', '/<link(.*?)href=(?:")http\:\/\/([^"]+)(?:")/i', '/<link(.*?)href=(?:")([^"]+)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+)(?:\@)/i' ); 369 $sub = array( 'src=@http://$1@', 'src=@$1@', 'src="' . $this->tpl_dir . '\\1"', 'src="$1"', 'background=@http://$1@', 'background=@$1@', 'background="' . $this->tpl_dir . '\\1"', 'background="$1"', '<link$1href=@http://$2@', '<link$1href=@$2@' , '<link$1href="' . $this->tpl_dir . '$2"', '<link$1href="$2"' ); 370 return preg_replace( $exp, $sub, $html ); 344 $exp = array( '/src=(?:")http\:\/\/([^"]+?)(?:")/i', '/src=(?:")([^"]+?)#(?:")/i', '/src="(.*?)"/', '/src=(?:\@)([^"]+?)(?:\@)/i', '/background=(?:")http\:\/\/([^"]+?)(?:")/i', '/background=(?:")([^"]+?)#(?:")/i', '/background="(.*?)"/', '/background=(?:\@)([^"]+?)(?:\@)/i', '/<link(.*?)href=(?:")http\:\/\/([^"]+?)(?:")/i', '/<link(.*?)href=(?:")([^"]+?)#(?:")/i', '/<link(.*?)href="(.*?)"/', '/<link(.*?)href=(?:\@)([^"]+?)(?:\@)/i' ); 345 $sub = array( 'src=@http://$1@', 'src=@$1@', 'src="' . $this->base_dir . '\\1"', 'src="$1"', 'background=@http://$1@', 'background=@$1@', 'background="' . $this->base_dir . '\\1"', 'background="$1"', '<link$1href=@http://$2@', '<link$1href=@$2@' , '<link$1href="' . $this->base_dir . '$2"', '<link$1href="$2"' ); 346 //return preg_replace( $exp, $sub, $html ); 347 return($html); 371 348 } 372 349 … … 374 351 375 352 /** 376 * Sostituisco le variabili con il codice php353 * Variable substitution 377 354 * 378 * @param string $html Html da sostituire379 * @param string $tag_left_delimiter Delimitatore sinistro del tag delle variabili. Di default ?{380 * @param string $tag_right_delimiter Delimitatore destro del tag delle variabili. Di default ?}381 * @param string $php_left_delimiter Delimitatore sinistro della sostituzione php. Es.<?php=382 * @param string $php_right_delimiter Delimitatore destro della sostituzione php. Es.;?>383 * @param string $loop_name Nome del loop384 * @return string Codice sostituito355 * @param string $html Html 356 * @param string $tag_left_delimiter default { 357 * @param string $tag_right_delimiter default } 358 * @param string $php_left_delimiter default <?php= 359 * @param string $php_right_delimiter default ;?> 360 * @param string $loop_name Loop name 361 * @return string Replaced code 385 362 */ 386 363 function var_replace( $html, $tag_left_delimiter, $tag_right_delimiter, $php_left_delimiter = null, $php_right_delimiter = null, $loop_name = null ){ 387 364 365 //all variables 388 366 $html = preg_replace( '/\{\#(\w+)\#\}/', $php_left_delimiter . '\\1' . $php_right_delimiter, $html ); 389 367 preg_match_all( '/' . $tag_left_delimiter . '\$(\w+(?:\.\${0,1}(?:\w+))*(?:\[\${0,1}(?:\w+)\])*(?:\-\>\${0,1}(?:\w+))*)(.*?)' . $tag_right_delimiter . '/', $html, $matches ); … … 391 369 for( $i = 0; $i < count( $matches[ 0 ] ); $i++ ){ 392 370 393 // inserisco nella variabile $tag il tag completo, es: {$news.title|substr:0,100}371 //complete tag ex: {$news.title|substr:0,100} 394 372 $tag = $matches[ 0 ][ $i ]; 395 396 // inserisco in $var la variabile es: news.title373 374 //variable name ex: news.title 397 375 $var = $matches[ 1 ][ $i ]; 398 376 399 // inserisco in $extra_var le eventuali funzioni associate alla variabile, es: substr:0,100377 //function and parameters associate to the variable ex: substr:0,100 400 378 $extra_var = $matches[ 2 ][ $i ]; 401 379 380 //function associate to variable 402 381 $function_var = ( $extra_var and $extra_var[0] == '|') ? substr( $extra_var, 1 ) : null; 403 382 404 // divido la variabile se ? un array (es. $news.title o $news[title]) o un oggetto (es. $news->title)383 //variable path split array (ex. $news.title o $news[title]) or object (ex. $news->title) 405 384 $temp = preg_split( "/\.|\[|\-\>/", $var ); 406 385 407 // prendo il nome della variabile386 //variable name 408 387 $var_name = $temp[ 0 ]; 409 388 410 // prendo gli elementi dell'array successivi al nome389 //variable path 411 390 $variable_path = substr( $var, strlen( $var_name ) ); 412 391 413 // trasformo le parentesi[ e ] in [" e in "]392 //parentesis transform [ e ] in [" e in "] 414 393 $variable_path = str_replace( '[', '["', $variable_path ); 415 394 $variable_path = str_replace( ']', '"]', $variable_path ); 416 395 417 //tra sformo .$variabile in ["$variabile"]396 //transform .$variable in ["$variable"] 418 397 $variable_path = preg_replace('/\.\$(\w+)/', '["$\\1"]', $variable_path ); 419 //trasformo [variabile] in ["variabile] 398 399 //transform [variable] in ["variable"] 420 400 $variable_path = preg_replace('/\.(\w+)/', '["\\1"]', $variable_path ); 421 401 422 // se alla funzione ? associata una funzione402 //if there's a function 423 403 if( $function_var ){ 424 404 425 // divido la funzione dai parametri (es:substr:0,100)405 //split function by function_name and parameters (ex substr:0,100) 426 406 $function_split = explode( ':', $function_var, 2 ); 427 407 428 // prendo la funzione408 //function name 429 409 $function = $function_split[ 0 ]; 430 410 431 // prendo i parametri411 //function parameters 432 412 $params = ( isset( $function_split[ 1 ] ) ) ? $function_split[ 1 ] : null; 433 413 … … 438 418 439 419 //if it is inside a loop 440 if( $loop_name ){ 441 442 //verify the variable name 443 if( $var_name == 'key' ) 444 $php_var = '$key' . $loop_name; 445 elseif( $var_name == 'value' ) 446 $php_var = '$value' . $loop_name . $variable_path; 447 elseif( $var_name == 'counter' ) 448 $php_var = '$counter' . $loop_name; 449 else 450 $php_var = '$var["' . $var_name . '"]' . $variable_path; 451 } 452 elseif( $var_name == 'GLOBALS' ) 420 if( $var_name == 'GLOBALS' ) 453 421 $php_var = '$GLOBALS' . $variable_path; 454 422 elseif( $var_name == '_SESSION' ) … … 462 430 elseif( $var_name == '_POST' ) 463 431 $php_var = '$_POST' . $variable_path; 432 elseif( $loop_name ){ 433 //verify the variable name 434 if( $var_name == 'key' ) 435 $php_var = '$key' . $loop_name; 436 elseif( $var_name == 'value' ) 437 $php_var = '$value' . $loop_name . $variable_path; 438 elseif( $var_name == 'counter' ) 439 $php_var = '$counter' . $loop_name; 440 else 441 $php_var = '$var["' . $var_name . '"]' . $variable_path; 442 } 464 443 else 465 444 $php_var = '$var["' . $var_name . '"]' . $variable_path; 466 467 445 468 446 if( isset( $function ) ) … … 477 455 478 456 479 return $html; 457 return $html; 480 458 } 481 459 modules/branches/2.9/endpointman/includes/template_manager.inc
r10240 r10792 69 69 } 70 70 71 $sql = 'SELECT endpointman_mac_list.id, endpointman_mac_list.mac, endpointman_mac_list.model, endpointman_line_list.description, endpointman_model_list.model as model_clone, endpointman_product_list.short_name as model_class FROM endpointman_mac_list, endpointman_model_list, endpointman_product_list, endpointman_line_list WHERE endpointman_mac_list.id = endpointman_line_list.mac_id AND endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.global_custom_cfg_data IS NOT NULL AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_mac_list.template_id = 0'; 71 $sql = 'SELECT endpointman_mac_list.mac, endpointman_mac_list.id, endpointman_mac_list.model, endpointman_model_list.model as model_clone, endpointman_product_list.short_name as model_class FROM endpointman_mac_list, endpointman_model_list, endpointman_product_list WHERE endpointman_product_list.id = endpointman_model_list.product_id AND endpointman_mac_list.global_custom_cfg_data IS NOT NULL AND endpointman_model_list.id = endpointman_mac_list.model AND endpointman_mac_list.template_id = 0'; 72 72 73 $template_list =& $db->getAll($sql, array(), DB_FETCHMODE_ASSOC); 73 74 foreach($template_list as $row) { 75 $sql = 'SELECT description , line FROM endpointman_line_list WHERE mac_id ='. $row['id'].' ORDER BY line ASC'; 76 $line_list =& $db->getAll($sql, array(), DB_FETCHMODE_ASSOC); 77 $description = ""; 78 $c = 0; 79 foreach($line_list as $line_row) { 80 if($c > 0) { 81 $description .= ", "; 82 } 83 $description .= $line_row['description']; 84 $c++; 85 } 74 86 $row_out[$i] = $row; 75 87 $row_out[$i]['custom'] = 1; 76 $row_out[$i]['name'] = $row['mac'] . "-(" .$ row['description'].")";88 $row_out[$i]['name'] = $row['mac'] . "-(" .$description.")"; 77 89 $i++; 78 90 } … … 89 101 $i++; 90 102 } 91 $ tpl = new RainTPL( LOCAL_PATH.'templates');92 $ tpl->assign("amp_conf_serial", "1");93 $ tpl->assign("templates_list", $row_out);94 $ tpl->assign("class_list", $class_row);95 $ tpl->assign("no_add", $no_add);96 $ tpl->assign("debug", $debug);103 $endpoint->tpl->assign("amp_conf_serial", "1"); 104 $endpoint->tpl->assign("templates_list", $row_out); 105 $endpoint->tpl->assign("class_list", $class_row); 106 $endpoint->tpl->assign("no_add", $no_add); 107 $endpoint->tpl->assign("debug", $debug); 108 $endpoint->tpl->assign("web_path", WEB_PATH); 97 109 98 110 foreach($endpoint->error as $key => $error) { … … 104 116 } 105 117 if(isset($error_message)) { 106 $endpoint->display_message_box($error_message,$ tpl,1);118 $endpoint->display_message_box($error_message,$endpoint->tpl,1); 107 119 } 108 120 if(isset($message)) { 109 $endpoint->display_message_box($message,$ tpl,0);121 $endpoint->display_message_box($message,$endpoint->tpl,0); 110 122 } 111 123 112 echo $ tpl->draw( 'template_manager' );124 echo $endpoint->tpl->draw( 'template_manager' ); 113 125 } modules/branches/2.9/endpointman/install.php
r10335 r10792 16 16 function outn($text) { 17 17 echo $text; 18 } 19 } 20 21 function epm_rmrf($dir) { 22 if(file_exists($dir)) { 23 $iterator = new RecursiveDirectoryIterator($dir); 24 foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) { 25 if ($file->isDir()) { 26 @rmdir($file->getPathname()); 27 } else { 28 @unlink($file->getPathname()); 29 } 30 } 31 //Remove parent path as the last step 32 @rmdir($dir); 18 33 } 19 34 } … … 77 92 } 78 93 79 $version = "2. 3.2";94 $version = "2.4.1"; 80 95 81 96 if(ep_table_exists("endpointman_global_vars")) { … … 147 162 } elseif($global_cfg['version'] == '2.3.8') { 148 163 $ver = "2.3.8"; 164 } elseif($global_cfg['version'] == '2.4.0') { 165 $ver = "2.4.0"; 166 } elseif($global_cfg['version'] == '2.4.1') { 167 $ver = "2.4.1"; 168 } elseif($global_cfg['version'] == '2.4.2') { 169 $ver = "2.4.2"; 149 170 } else { 150 171 $ver = "1000"; … … 175 196 $sql_update_vars = "INSERT INTO `endpointman_global_vars` (`idnum`, `var_name`, `value`) VALUES 176 197 (5, 'config_location', '/tftpboot/'), 177 (6, 'update_server', 'http://www.provisioner.net/release /'),198 (6, 'update_server', 'http://www.provisioner.net/release3/'), 178 199 (7, 'version', '2.0.0'), 179 200 (8, 'enable_ari', '0'), … … 742 763 $db->query($sql); 743 764 } 744 } if745 ($ver <= "2.2.3") {765 } 766 if ($ver <= "2.2.3") { 746 767 $sql = "UPDATE endpointman_global_vars SET value = 'http://www.provisioner.net/release/' WHERE var_name = 'update_server'"; 747 768 $db->query($sql); … … 766 787 if ($ver <= "2.2.6") { 767 788 $sql = "CREATE TABLE IF NOT EXISTS `endpointman_line_list` ( 768 `luid` int(11) NOT NULL AUTO_INCREMENT,769 `mac_id` int(11) NOT NULL,770 `line` smallint(2) NOT NULL,771 `ext` varchar(15) NOT NULL,772 `description` varchar(20) NOT NULL,773 `custom_cfg_data` longblob NOT NULL,774 `user_cfg_data` longblob NOT NULL,775 PRIMARY KEY (`luid`)776 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";789 `luid` int(11) NOT NULL AUTO_INCREMENT, 790 `mac_id` int(11) NOT NULL, 791 `line` smallint(2) NOT NULL, 792 `ext` varchar(15) NOT NULL, 793 `description` varchar(20) NOT NULL, 794 `custom_cfg_data` longblob NOT NULL, 795 `user_cfg_data` longblob NOT NULL, 796 PRIMARY KEY (`luid`) 797 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;"; 777 798 $db->query($sql); 778 799 … … 829 850 } 830 851 831 if ($ver <= '2.2.9') { 832 833 } 834 835 if ($ver <= '2.3.0') { 836 837 } 838 839 if ($ver <= '2.3.1') { 840 841 } 852 if ($ver <= "2.4.0") { 853 out("Uninstalling All Installed Brands (You'll just simply have to update again, no loss of data)"); 854 $db->query("UPDATE endpointman_brand_list SET installed = '0'"); 855 out("Changing update server"); 856 $sql = "UPDATE endpointman_global_vars SET value = 'http://www.provisioner.net/release3/' WHERE var_name ='update_server'"; 857 $db->query($sql); 858 $sql = "UPDATE endpointman_model_list SET enabled = '0'"; 859 $db->query($sql); 860 861 exec("rm -Rf ".PHONE_MODULES_PATH); 862 863 if(!file_exists(PHONE_MODULES_PATH)) { 864 mkdir(PHONE_MODULES_PATH, 0764); 865 out("Creating Phone Modules Directory"); 866 } 867 868 if(!file_exists(PHONE_MODULES_PATH."setup.php")) { 869 copy(LOCAL_PATH."install/setup.php",PHONE_MODULES_PATH."setup.php"); 870 out("Moving Auto Provisioner Class"); 871 } 872 873 if(!file_exists(PHONE_MODULES_PATH."temp/")) { 874 mkdir(PHONE_MODULES_PATH."temp/", 0764); 875 out("Creating temp folder"); 876 } 877 } 878 842 879 } 843 880 … … 892 929 (4, 'gmthr', ''), 893 930 (5, 'config_location', '/tftpboot/'), 894 (6, 'update_server', 'http://www.provisioner.net/release /'),931 (6, 'update_server', 'http://www.provisioner.net/release3/'), 895 932 (7, 'version', '".$version."'), 896 933 (8, 'enable_ari', '0'), … … 1153 1190 out("Fixing permissions on ARI module"); 1154 1191 chmod($amp_conf['AMPWEBROOT']."/recordings/modules/phonesettings.module", 0664); 1155 } 1156 } 1192 1193 } 1194 $sql = "UPDATE endpointman_global_vars SET value = 'http://www.provisioner.net/release3/' WHERE var_name = 'update_server'"; 1195 $db->query($sql); 1196 } modules/branches/2.9/endpointman/install/phonesettings.module
r10331 r10792 1 <?PHP 2 1 <?php 3 2 /** 4 3 * Endpoint Manager ARI File … … 9 8 */ 10 9 11 12 13 10 /** 14 11 * @file … … 17 14 18 15 /** 19 * Class for settings20 */16 * Class for settings 17 */ 21 18 class phonesettings { 22 23 /* 19 /* 24 20 * rank (for prioritizing modules) 25 */26 function rank() {27 28 $rank = 10;29 return $rank;30 }31 32 /*21 */ 22 function rank() { 23 24 $rank = 10; 25 return $rank; 26 } 27 28 /* 33 29 * init 34 */35 function init() {36 }37 38 /*30 */ 31 function init() { 32 } 33 34 /* 39 35 * Adds menu item to nav menu 40 36 * 41 37 * @param $args 42 38 * Common arguments 43 */44 function navMenu($args) {45 46 $ret = "";47 $exten = $_SESSION['ari_user']['extension'];48 49 $sql = "SELECT * FROM endpointman_global_vars WHERE var_name = 'enable_ari'";50 $results = $_SESSION['dbh_asterisk']->getAll($sql, DB_FETCHMODE_ASSOC);51 52 // and we are not logged in as admin53 if (($exten!=$ARI_ADMIN_USERNAME) AND ($results[0]['value'])) {54 $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=phonesettings&f=display'>" . _("Phone Settings") . "</a></small></small></p><br>";55 }56 57 return $ret;58 }59 60 /*39 */ 40 function navMenu($args) { 41 42 $ret = ""; 43 $exten = $_SESSION['ari_user']['extension']; 44 45 $sql = "SELECT * FROM endpointman_global_vars WHERE var_name = 'enable_ari'"; 46 $results = $_SESSION['dbh_asterisk']->getAll($sql, DB_FETCHMODE_ASSOC); 47 48 // and we are not logged in as admin 49 if (($exten!=$ARI_ADMIN_USERNAME) AND ($results[0]['value'])) { 50 $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=phonesettings&f=display'>" . _("Phone Settings") . "</a></small></small></p><br>"; 51 } 52 53 return $ret; 54 } 55 56 /* 61 57 * Acts on the user settings 62 58 * … … 65 61 * @param $a 66 62 * action 67 */ 68 function action($args) { 69 global $endpoint, $global_cfg; 70 71 $doc_root = $_SERVER["DOCUMENT_ROOT"] ."/admin/modules/endpointman/"; 72 require($doc_root . "includes/functions.inc"); 73 74 $endpoint = new endpointmanager(); 75 76 $sql = "SELECT mac_id, line FROM endpointman_line_list WHERE ext = '".$_SESSION['ari_user']['extension']."' "; 77 $mac_row =& $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 78 79 $mac_id = $mac_row['mac_id']; 80 $line = $mac_row['line']; 81 82 $row = $endpoint->get_phone_info($mac_id); 83 84 $cfg_data = unserialize($row['template_data']); 85 86 $custom_cfg_data2 = unserialize($row['global_custom_cfg_data']); 87 88 $count = count($cfg_data); 89 for($i=0;$i<=$count;$i++) { 90 $temping = str_replace('$','',$cfg_data[$i]['variable']); 91 if((isset($_REQUEST[$temping])) AND (isset($custom_cfg_data2[$temping]['ari'])) AND ($custom_cfg_data2[$temping]['ari'] == 1)) { 92 $custom_cfg_data[$temping]['value'] = $_REQUEST[$temping]; 93 } 94 } 95 96 $custom_cfg_data = serialize($custom_cfg_data); 97 98 $sql = "UPDATE endpointman_mac_list SET global_user_cfg_data = '".$custom_cfg_data."' WHERE id = ". $mac_id; 99 $endpoint->db->query($sql); 100 101 //refresh the data before we prepare so we get acurate data 102 $row['global_user_cfg_data'] = $custom_cfg_data; 103 $endpoint->prepare_configs($row); 104 105 $m = "phonesettings"; 106 107 $ret .= " 63 */ 64 function action($args) { 65 global $endpoint, $global_cfg; 66 67 $doc_root = $_SERVER["DOCUMENT_ROOT"] ."/admin/modules/endpointman/"; 68 require($doc_root . "includes/functions.inc"); 69 70 $endpoint = new endpointmanager(); 71 72 $sql = "SELECT mac_id, line FROM endpointman_line_list WHERE ext = '".$_SESSION['ari_user']['extension']."' "; 73 $mac_row =& $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 74 75 $mac_id = $mac_row['mac_id']; 76 $line = $mac_row['line']; 77 78 $row = $endpoint->get_phone_info($mac_id); 79 80 $cfg_data = unserialize($row['template_data']); 81 82 $custom_cfg_data2 = unserialize($row['global_custom_cfg_data']); 83 84 if($row['template_id'] > 0) { 85 $custom_cfg_data2 = unserialize($row['template_data_info']['global_custom_cfg_data']); 86 } else { 87 $custom_cfg_data2 = unserialize($row['global_custom_cfg_data']); 88 } 89 90 if (!empty($custom_cfg_data2)) { 91 if(array_key_exists('data', $custom_cfg_data2)) { 92 $custom_cfg_data_data = $custom_cfg_data2['data']; 93 $custom_cfg_data_ari = $custom_cfg_data2['ari']; 94 } else { 95 $custom_cfg_data_data = array(); 96 $custom_cfg_data_ari = array(); 97 } 98 } 99 100 $custom_cfg_data = array(); 101 foreach($custom_cfg_data_ari as $key => $data) { 102 if(isset($_REQUEST[$key])) { 103 $custom_cfg_data[$key] = $_REQUEST[$key]; 104 } 105 } 106 107 /* 108 foreach($cfg_data as $config_options) { 109 switch ($config_options['type']) { 110 case "loop": 111 $loop_start = $config_options['loop_start']; 112 $loop_end = $config_options['loop_end']; 113 for($a=$loop_start;$a<=$loop_end;$a++) { 114 foreach($config_options['data']['item'] as $items) { 115 $temping = str_replace('$','',$items['variable'])."_".$a; 116 if((isset($_REQUEST[$temping])) AND (isset($custom_cfg_data_ari[$temping])) AND ($custom_cfg_data_ari[$temping] == 1)) { 117 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 118 } 119 } 120 } 121 break; 122 case "input": 123 case "radio": 124 case "list": 125 $temping = str_replace('$','',$config_options['variable']); 126 if((isset($_REQUEST[$temping])) AND (isset($custom_cfg_data_ari[$temping])) AND ($custom_cfg_data_ari[$temping] == 1)) { 127 $custom_cfg_data[$temping] = $_REQUEST[$temping]; 128 } 129 break; 130 default: 131 break; 132 } 133 } 134 * 135 */ 136 137 $custom_cfg_data = serialize($custom_cfg_data); 138 139 $sql = "UPDATE endpointman_mac_list SET global_user_cfg_data = '".$custom_cfg_data."' WHERE id = ". $mac_id; 140 $endpoint->db->query($sql); 141 142 //refresh the data before we prepare so we get acurate data 143 $row['global_user_cfg_data'] = $custom_cfg_data; 144 $endpoint->prepare_configs($row); 145 146 $m = "phonesettings"; 147 148 $ret .= " 108 149 <head> 109 150 <script> … … 114 155 </head>"; 115 156 116 return $ret;117 }118 119 function reloadSettings($exten) {120 121 }122 123 /*157 return $ret; 158 } 159 160 function reloadSettings($exten) { 161 162 } 163 164 /* 124 165 * Displays stats page 125 166 * 126 167 * @param $args 127 168 * Common arguments 128 */ 129 function display($args) { 130 if (!isset($_SESSION['dbh_asterisk'])) { 131 die('No Database?'); 132 } 133 134 $doc_root = $_SERVER["DOCUMENT_ROOT"] ."/admin/modules/endpointman/"; 135 require($doc_root . "includes/functions.inc"); 136 137 $endpoint = new endpointmanager(); 138 139 $sql = "SELECT mac_id, line FROM endpointman_line_list WHERE ext = '".$_SESSION['ari_user']['extension']."' "; 140 $mac_row =& $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 141 142 $mac_id = $mac_row['mac_id']; 143 $line = $mac_row['line']; 144 145 $row = $endpoint->get_phone_info($mac_id); 146 147 if(!$endpoint->sync_model($row['model_id'])) { 148 die("unable to sync local template files"); 149 } 150 151 $brand_name = $row['directory']; 152 $model_name = $row['cfg_dir']; 153 154 155 //Start the display of the html file in the product folder 156 157 $template = '<h3>Hello '. $row['line'][$line]['description'] . ', You are currently editing phone settings for extension '.$row['line'][$line]['ext'].'</h3><br />'; 158 159 $out = $endpoint->generate_gui_html($row['template_data'],$row['global_custom_cfg_data'],FALSE,$row['global_user_cfg_data']); 160 161 if(!empty($out)) { 162 $out[0]['data'] = array_values($out[0]['data']); 163 $out[0]['title'] = "Your Phone Settings"; 164 $button = "<input name='submit' type='submit' value='Save & Reboot'>"; 165 166 } else { 167 $out[0]['title'] = "Your Phone Settings have not been enabled. Please talk to your administrator."; 168 $out[0]['data'] = NULL; 169 $button = ""; 170 } 171 172 $tpl = new RainTPL( LOCAL_PATH.'templates' ); 173 174 $tpl->assign("in_ari", 1); 175 $tpl->assign("template_editor", $out); 176 $tpl->assign("hidden_id", $row['line'][$line]['luid']); 177 $template .= $tpl->draw( 'template_editor', TRUE ); 178 179 180 $m = "phonesettings"; 181 $ret = "<form class='phonesettings' name='ari_settings' action='' method='GET'> 182 <input type=hidden name=m value=" . $m . "> 183 <input type=hidden name=f value='action'> 184 <input type=hidden name=a value='update'> 185 <br> 186 " . $template . " 187 <br>". $button ."</form>"; 188 return($ret); 189 } 190 } // class 169 */ 170 function display($args) { 171 if (!isset($_SESSION['dbh_asterisk'])) { 172 die('No Database?'); 173 } 174 175 $doc_root = $_SERVER["DOCUMENT_ROOT"] ."/admin/modules/endpointman/"; 176 require($doc_root . "includes/functions.inc"); 177 178 $endpoint = new endpointmanager(); 179 180 $sql = "SELECT mac_id, line FROM endpointman_line_list WHERE ext = '".$_SESSION['ari_user']['extension']."' "; 181 182 $res =& $endpoint->db->query($sql); 183 if($res->numRows()) { 184 185 $mac_row =& $endpoint->db->getRow($sql, array(), DB_FETCHMODE_ASSOC); 186 187 $mac_id = $mac_row['mac_id']; 188 $line = $mac_row['line']; 189 190 $row = $endpoint->get_phone_info($mac_id); 191 192 if(!$endpoint->sync_model($row['model_id'])) { 193 die("unable to sync local template files"); 194 } 195 196 $brand_name = $row['directory']; 197 $model_name = $row['cfg_dir']; 198 199 $ari = unserialize($row['global_custom_cfg_data']); 200 if(!empty($ari['ari'])) { 201 //Start the display of the html file in the product folder 202 203 $template = '<h3>Hello '. $row['line'][$line]['description'] . ', You are currently editing phone settings for extension '.$row['line'][$line]['ext'].'</h3><br />'; 204 205 if($row['template_id'] > 0) { 206 $out = $endpoint->generate_gui_html($row['template_data'],$row['template_data_info']['global_custom_cfg_data'],FALSE,$row['global_user_cfg_data'],NULL,$_SESSION['ari_user']['extension']); 207 } else { 208 $out = $endpoint->generate_gui_html($row['template_data'],$row['global_custom_cfg_data'],FALSE,$row['global_user_cfg_data'],NULL,$_SESSION['ari_user']['extension']); 209 } 210 211 if(!empty($out)) { 212 $out[0]['data'] = array_values($out[0]['data']); 213 $button = "<input name='submit' type='submit' value='Save & Reboot'>"; 214 } else { 215 $out[0]['title'] = "Your Phone Settings have not been enabled. Please talk to your administrator."; 216 $out[0]['data'] = NULL; 217 $button = ""; 218 } 219 220 $endpoint->tpl->assign("in_ari", 1); 221 $endpoint->tpl->assign("template_editor", $out); 222 $endpoint->tpl->assign("hidden_id", $row['line'][$line]['luid']); 223 $template .= $endpoint->tpl->draw( 'template_editor', TRUE ); 224 225 226 $m = "phonesettings"; 227 $ret = "<form class='phonesettings' name='ari_settings' action='' method='GET'> 228 <input type=hidden name=m value=" . $m . "> 229 <input type=hidden name=f value='action'> 230 <input type=hidden name=a value='update'> 231 <br> 232 " . $template . " 233 <br>". $button ."</form>"; 234 return($ret); 235 } else { 236 $m = "phonesettings"; 237 $ret = "<h3>This User/Extension has no settings defined for you to control, Please talk to your administrator</h3>"; 238 return($ret); 239 } 240 } else { 241 $m = "phonesettings"; 242 $ret = "<h3>This User/Extension is not managed by Endpoint Manager, Please talk to your administrator</h3>"; 243 return($ret); 244 } 245 } 246 } modules/branches/2.9/endpointman/module.xml
r10689 r10792 2 2 <rawname>endpointman</rawname> 3 3 <name>PBX End Point Manager</name> 4 <version>2.9.0. 0</version>4 <version>2.9.0.1</version> 5 5 <type>tool</type> 6 6 <category>End Point Manager</category> 7 7 <publisher>Andrew Nagy</publisher> 8 <license> GPLv2</license>8 <license>MPLv1.1</license> 9 9 <menuitems> 10 10 <epm_devices sort="1">End Point Device List</epm_devices> … … 15 15 <description>PBX End Point Manager supports automated deployment of multiple manufacturers IP telephones.</description> 16 16 <changelog> 17 *2.9.0.0* bumped for 2.9, removed errors in module.xml causing erors for online xml parsing 18 *2.3.2* Various Bug Fixes 19 *2.3.1* Install directory case corrections 20 *2.3.0* No Changes 21 *2.2.9* Fixed ARI module, Update Local Description on Rebuild, Fix Firmware Updater 22 *2.2.8* Fixed User & Devices error. 23 *2.2.6* Fixed download progress so that it displays. 24 *2.2.5* Fixed Debug Always on Error, File download errors, Fix float error on install 25 *2.2.0* Stopped using iframe installer, switched to freepbx version 26 </changelog> 17 *2.9.0.0* bumped for 2.9, removed errors in module.xml causing erors for online xml parsing 18 *2.3.2* Various Bug Fixes 19 *2.3.1* Install directory case corrections 20 *2.3.0* No Changes 21 </changelog> 27 22 <info>http://projects.colsolgrp.net/projects/show/endpointman</info> 28 <location> release/2.9/endpointman-2.9.0.0.tgz</location>23 <location>contributed_modules/release/endpointman-2.3.2.tgz</location> 29 24 30 <md5sum> a11032a057cef3da4e915d1600dbf811</md5sum>25 <md5sum>b0e3a14a20449b0441d1a9f432f19559</md5sum> 31 26 </module>
