| 883 | | if(!class_exists('ProvisionerConfig')) { |
|---|
| 884 | | require(PHONE_MODULES_PATH.'setup.php'); |
|---|
| 885 | | } |
|---|
| 886 | | |
|---|
| 887 | | //Load Provisioner |
|---|
| 888 | | $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; |
|---|
| 889 | | $provisioner_lib = new $class(); |
|---|
| 890 | | |
|---|
| 891 | | //Tell the system who we are and were to find the data. |
|---|
| 892 | | $provisioner_lib->root_dir = PHONE_MODULES_PATH; |
|---|
| 893 | | $provisioner_lib->engine = 'asterisk'; |
|---|
| 894 | | $provisioner_lib->engine_location = $this->global_cfg['asterisk_location']; |
|---|
| 895 | | $provisioner_lib->system = 'unix'; |
|---|
| 896 | | |
|---|
| 897 | | //have to because of versions less than php5.3 |
|---|
| 898 | | $provisioner_lib->brand_name = $phone_info['directory']; |
|---|
| 899 | | $provisioner_lib->family_line = $phone_info['cfg_dir']; |
|---|
| 900 | | |
|---|
| 901 | | //Mac Address |
|---|
| 902 | | $provisioner_lib->mac = $phone_info['mac']; |
|---|
| 903 | | |
|---|
| 904 | | //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models) |
|---|
| 905 | | //This has to match word for word. I really need to fix this.... |
|---|
| 906 | | $provisioner_lib->model = $phone_info['model']; |
|---|
| 907 | | |
|---|
| 908 | | //Timezone |
|---|
| 909 | | $provisioner_lib->timezone = $this->global_cfg['tz']; |
|---|
| 910 | | |
|---|
| 911 | | //Server IP |
|---|
| 912 | | $provisioner_lib->server[1]['ip'] = $this->global_cfg['srvip']; |
|---|
| 913 | | $provisioner_lib->server[1]['port'] = 5060; |
|---|
| 914 | | |
|---|
| 915 | | $temp = ""; |
|---|
| 916 | | $template_data = unserialize($phone_info['template_data']); |
|---|
| 917 | | $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']); |
|---|
| 918 | | if($phone_info['template_id'] > 0) { |
|---|
| 919 | | $global_custom_cfg_data = unserialize($phone_info['template_data_info']['global_custom_cfg_data']); |
|---|
| 920 | | //Provide alternate Configuration file instead of the one from the hard drive |
|---|
| 921 | | if(!empty($phone_info['template_data_info']['config_files_override'])) { |
|---|
| 922 | | $temp = unserialize($phone_info['template_data_info']['config_files_override']); |
|---|
| 923 | | foreach($temp as $list) { |
|---|
| 924 | | $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; |
|---|
| 925 | | $res =& $this->db->query($sql); |
|---|
| 926 | | if($res->numRows()) { |
|---|
| 927 | | $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| 928 | | $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; |
|---|
| 929 | | } |
|---|
| 930 | | } |
|---|
| 931 | | } |
|---|
| 932 | | } else { |
|---|
| 933 | | $global_custom_cfg_data = unserialize($phone_info['global_custom_cfg_data']); |
|---|
| 934 | | //Provide alternate Configuration file instead of the one from the hard drive |
|---|
| 935 | | if(!empty($phone_info['config_files_override'])) { |
|---|
| 936 | | $temp = unserialize($phone_info['config_files_override']); |
|---|
| 937 | | foreach($temp as $list) { |
|---|
| 938 | | $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; |
|---|
| 939 | | $res =& $this->db->query($sql); |
|---|
| 940 | | if($res->numRows()) { |
|---|
| 941 | | $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| 942 | | $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; |
|---|
| 943 | | } |
|---|
| 944 | | } |
|---|
| 945 | | } |
|---|
| 946 | | } |
|---|
| 947 | | |
|---|
| 948 | | if (!empty($global_custom_cfg_data)) { |
|---|
| 949 | | if(array_key_exists('data', $global_custom_cfg_data)) { |
|---|
| 950 | | $global_custom_cfg_ari = $global_custom_cfg_data['ari']; |
|---|
| 951 | | $global_custom_cfg_data = $global_custom_cfg_data['data']; |
|---|
| 952 | | } else { |
|---|
| 953 | | $global_custom_cfg_data = array(); |
|---|
| 954 | | $global_custom_cfg_ari = array(); |
|---|
| 955 | | } |
|---|
| 956 | | } |
|---|
| 957 | | |
|---|
| 958 | | $new_template_data = array(); |
|---|
| 959 | | $line_ops = array(); |
|---|
| 960 | | if(is_array($global_custom_cfg_data)) { |
|---|
| 961 | | foreach($global_custom_cfg_data as $key => $data) { |
|---|
| 962 | | $full_key = $key; |
|---|
| 963 | | $key = explode('|',$key); |
|---|
| 964 | | $count = count($key); |
|---|
| 965 | | switch($count) { |
|---|
| 966 | | case 1: |
|---|
| 967 | | if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { |
|---|
| 968 | | $new_template_data[$full_key] = $global_user_cfg_data[$full_key]; |
|---|
| 969 | | } else { |
|---|
| 970 | | $new_template_data[$full_key] = $global_custom_cfg_data[$full_key]; |
|---|
| 971 | | } |
|---|
| 972 | | break; |
|---|
| 973 | | case 2: |
|---|
| 974 | | $breaks = explode('_',$key[1]); |
|---|
| 975 | | if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { |
|---|
| 976 | | $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key]; |
|---|
| 977 | | } else { |
|---|
| 978 | | $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key]; |
|---|
| 979 | | } |
|---|
| 980 | | break; |
|---|
| 981 | | case 3: |
|---|
| 982 | | if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { |
|---|
| 983 | | $line_ops[$key[1]][$key[2]] = $global_user_cfg_data[$full_key]; |
|---|
| 984 | | } else { |
|---|
| 985 | | $line_ops[$key[1]][$key[2]] = $global_custom_cfg_data[$full_key]; |
|---|
| 986 | | } |
|---|
| 987 | | break; |
|---|
| 988 | | } |
|---|
| 989 | | } |
|---|
| 990 | | } |
|---|
| 991 | | |
|---|
| 992 | | //Loop through Lines! |
|---|
| 993 | | foreach($phone_info['line'] as $line) { |
|---|
| 994 | | $provisioner_lib->lines[$line['line']] = array('ext' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description']); |
|---|
| 995 | | if(isset($line_ops[$line['line']])) { |
|---|
| 996 | | $provisioner_lib->lines[$line['line']]['options'] = $line_ops[$line['line']]; |
|---|
| 997 | | } |
|---|
| 998 | | } |
|---|
| 999 | | |
|---|
| 1000 | | //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create |
|---|
| 1001 | | //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included |
|---|
| 1002 | | //line 'global' will set variables that aren't line dependant |
|---|
| 1003 | | $provisioner_lib->options = $new_template_data; |
|---|
| 1004 | | |
|---|
| 1005 | | //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed |
|---|
| 1006 | | //and if they have defaults assigned in a future template_data.xml or in the config file using pipes (|) those will be used, pipes take precedence |
|---|
| 1007 | | $provisioner_lib->processor_info = "EndPoint Manager Version ".$this->global_cfg['version']; |
|---|
| 1008 | | |
|---|
| 1009 | | // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is |
|---|
| 1010 | | //Start timer |
|---|
| 1011 | | $time_start = microtime(true); |
|---|
| 1012 | | $returned_data = $provisioner_lib->generate_config(); |
|---|
| 1013 | | //End timer |
|---|
| 1014 | | $time_end = microtime(true); |
|---|
| 1015 | | $time = $time_end - $time_start; |
|---|
| 1016 | | if($time > 360) { |
|---|
| 1017 | | $this->error['generate_time'] = "It took an awfully long time to generate configs...(".round($time,2)." seconds)"; |
|---|
| 1018 | | } |
|---|
| 1019 | | //Create Directory Structure (If needed) |
|---|
| 1020 | | if(isset($provisioner_lib->directory_structure)) { |
|---|
| 1021 | | foreach($provisioner_lib->directory_structure as $data) { |
|---|
| 1022 | | $dir = $this->global_cfg['config_location'] . $data; |
|---|
| 1023 | | if(!file_exists($dir)) { |
|---|
| 1024 | | mkdir($dir, 0777); |
|---|
| 1025 | | } |
|---|
| 1026 | | } |
|---|
| 1027 | | } |
|---|
| 1028 | | |
|---|
| 1029 | | //Copy Files/Directories (If needed) |
|---|
| 1030 | | if(isset($provisioner_lib->copy_files)) { |
|---|
| 1031 | | foreach($provisioner_lib->copy_files as $data) { |
|---|
| 1032 | | if(((file_exists($this->global_cfg['config_location'].$data)) AND (!in_array($data,$provisioner_lib->protected_files))) OR (!file_exists($this->global_cfg['config_location'].$data))) { |
|---|
| 1033 | | if(is_dir(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data)) { |
|---|
| 1034 | | if(!file_exists($this->global_cfg['config_location'].$data)) { |
|---|
| 1035 | | if (!@mkdir($this->global_cfg['config_location'].$data, 0777)) { |
|---|
| 1036 | | $this->error['parse_configs'] = "Could Not Create Directory: ".$data; |
|---|
| | 883 | if(file_exists(PHONE_MODULES_PATH.'setup.php')) { |
|---|
| | 884 | if(!class_exists('ProvisionerConfig')) { |
|---|
| | 885 | require(PHONE_MODULES_PATH.'setup.php'); |
|---|
| | 886 | } |
|---|
| | 887 | |
|---|
| | 888 | //Load Provisioner |
|---|
| | 889 | $class = "endpoint_" . $phone_info['directory'] . "_" . $phone_info['cfg_dir'] . '_phone'; |
|---|
| | 890 | if(class_exists($class)) { |
|---|
| | 891 | $provisioner_lib = new $class(); |
|---|
| | 892 | |
|---|
| | 893 | //Tell the system who we are and were to find the data. |
|---|
| | 894 | $provisioner_lib->root_dir = PHONE_MODULES_PATH; |
|---|
| | 895 | $provisioner_lib->engine = 'asterisk'; |
|---|
| | 896 | $provisioner_lib->engine_location = $this->global_cfg['asterisk_location']; |
|---|
| | 897 | $provisioner_lib->system = 'unix'; |
|---|
| | 898 | |
|---|
| | 899 | //have to because of versions less than php5.3 |
|---|
| | 900 | $provisioner_lib->brand_name = $phone_info['directory']; |
|---|
| | 901 | $provisioner_lib->family_line = $phone_info['cfg_dir']; |
|---|
| | 902 | |
|---|
| | 903 | //Mac Address |
|---|
| | 904 | $provisioner_lib->mac = $phone_info['mac']; |
|---|
| | 905 | |
|---|
| | 906 | //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models) |
|---|
| | 907 | //This has to match word for word. I really need to fix this.... |
|---|
| | 908 | $provisioner_lib->model = $phone_info['model']; |
|---|
| | 909 | |
|---|
| | 910 | //Timezone |
|---|
| | 911 | $provisioner_lib->timezone = $this->global_cfg['tz']; |
|---|
| | 912 | |
|---|
| | 913 | //Server IP |
|---|
| | 914 | $provisioner_lib->server[1]['ip'] = $this->global_cfg['srvip']; |
|---|
| | 915 | $provisioner_lib->server[1]['port'] = 5060; |
|---|
| | 916 | |
|---|
| | 917 | $temp = ""; |
|---|
| | 918 | $template_data = unserialize($phone_info['template_data']); |
|---|
| | 919 | $global_user_cfg_data = unserialize($phone_info['global_user_cfg_data']); |
|---|
| | 920 | if($phone_info['template_id'] > 0) { |
|---|
| | 921 | $global_custom_cfg_data = unserialize($phone_info['template_data_info']['global_custom_cfg_data']); |
|---|
| | 922 | //Provide alternate Configuration file instead of the one from the hard drive |
|---|
| | 923 | if(!empty($phone_info['template_data_info']['config_files_override'])) { |
|---|
| | 924 | $temp = unserialize($phone_info['template_data_info']['config_files_override']); |
|---|
| | 925 | foreach($temp as $list) { |
|---|
| | 926 | $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; |
|---|
| | 927 | $res =& $this->db->query($sql); |
|---|
| | 928 | if($res->numRows()) { |
|---|
| | 929 | $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 930 | $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; |
|---|
| 1039 | | $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/"); |
|---|
| 1040 | | $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); |
|---|
| 1041 | | // could use CHILD_FIRST if you so wish |
|---|
| 1042 | | foreach ($iterator as $file) { |
|---|
| 1043 | | if(is_dir($file)) { |
|---|
| 1044 | | $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); |
|---|
| 1045 | | if(!file_exists($this->global_cfg['config_location'].$data."/".$dir)) { |
|---|
| 1046 | | if (!@mkdir($this->global_cfg['config_location'].$data."/".$dir, 0777)) { |
|---|
| 1047 | | $this->error['parse_configs'] = "Could Not Create Directory: ".$data."/".$dir; |
|---|
| | 933 | } |
|---|
| | 934 | } else { |
|---|
| | 935 | $global_custom_cfg_data = unserialize($phone_info['global_custom_cfg_data']); |
|---|
| | 936 | //Provide alternate Configuration file instead of the one from the hard drive |
|---|
| | 937 | if(!empty($phone_info['config_files_override'])) { |
|---|
| | 938 | $temp = unserialize($phone_info['config_files_override']); |
|---|
| | 939 | foreach($temp as $list) { |
|---|
| | 940 | $sql = "SELECT original_name,data FROM endpointman_custom_configs WHERE id = ".$list; |
|---|
| | 941 | $res =& $this->db->query($sql); |
|---|
| | 942 | if($res->numRows()) { |
|---|
| | 943 | $data = $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 944 | $provisioner_lib->config_files_override[$data['original_name']] = $data['data']; |
|---|
| | 945 | } |
|---|
| | 946 | } |
|---|
| | 947 | } |
|---|
| | 948 | } |
|---|
| | 949 | |
|---|
| | 950 | if (!empty($global_custom_cfg_data)) { |
|---|
| | 951 | if(array_key_exists('data', $global_custom_cfg_data)) { |
|---|
| | 952 | $global_custom_cfg_ari = $global_custom_cfg_data['ari']; |
|---|
| | 953 | $global_custom_cfg_data = $global_custom_cfg_data['data']; |
|---|
| | 954 | } else { |
|---|
| | 955 | $global_custom_cfg_data = array(); |
|---|
| | 956 | $global_custom_cfg_ari = array(); |
|---|
| | 957 | } |
|---|
| | 958 | } |
|---|
| | 959 | |
|---|
| | 960 | $new_template_data = array(); |
|---|
| | 961 | $line_ops = array(); |
|---|
| | 962 | if(is_array($global_custom_cfg_data)) { |
|---|
| | 963 | foreach($global_custom_cfg_data as $key => $data) { |
|---|
| | 964 | $full_key = $key; |
|---|
| | 965 | $key = explode('|',$key); |
|---|
| | 966 | $count = count($key); |
|---|
| | 967 | switch($count) { |
|---|
| | 968 | case 1: |
|---|
| | 969 | if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { |
|---|
| | 970 | $new_template_data[$full_key] = $global_user_cfg_data[$full_key]; |
|---|
| | 971 | } else { |
|---|
| | 972 | $new_template_data[$full_key] = $global_custom_cfg_data[$full_key]; |
|---|
| | 973 | } |
|---|
| | 974 | break; |
|---|
| | 975 | case 2: |
|---|
| | 976 | $breaks = explode('_',$key[1]); |
|---|
| | 977 | if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { |
|---|
| | 978 | $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_user_cfg_data[$full_key]; |
|---|
| | 979 | } else { |
|---|
| | 980 | $new_template_data[$breaks[0]][$breaks[2]][$breaks[1]] = $global_custom_cfg_data[$full_key]; |
|---|
| | 981 | } |
|---|
| | 982 | break; |
|---|
| | 983 | case 3: |
|---|
| | 984 | if(($this->global_cfg['enable_ari'] == 1) AND (isset($global_custom_cfg_ari[$full_key])) AND (isset($global_user_cfg_data[$full_key]))) { |
|---|
| | 985 | $line_ops[$key[1]][$key[2]] = $global_user_cfg_data[$full_key]; |
|---|
| | 986 | } else { |
|---|
| | 987 | $line_ops[$key[1]][$key[2]] = $global_custom_cfg_data[$full_key]; |
|---|
| | 988 | } |
|---|
| | 989 | break; |
|---|
| | 990 | } |
|---|
| | 991 | } |
|---|
| | 992 | } |
|---|
| | 993 | |
|---|
| | 994 | //Loop through Lines! |
|---|
| | 995 | foreach($phone_info['line'] as $line) { |
|---|
| | 996 | $provisioner_lib->lines[$line['line']] = array('ext' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description']); |
|---|
| | 997 | if(isset($line_ops[$line['line']])) { |
|---|
| | 998 | $provisioner_lib->lines[$line['line']]['options'] = $line_ops[$line['line']]; |
|---|
| | 999 | } |
|---|
| | 1000 | } |
|---|
| | 1001 | |
|---|
| | 1002 | //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create |
|---|
| | 1003 | //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included |
|---|
| | 1004 | //line 'global' will set variables that aren't line dependant |
|---|
| | 1005 | $provisioner_lib->options = $new_template_data; |
|---|
| | 1006 | |
|---|
| | 1007 | //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed |
|---|
| | 1008 | //and if they have defaults assigned in a future template_data.xml or in the config file using pipes (|) those will be used, pipes take precedence |
|---|
| | 1009 | $provisioner_lib->processor_info = "EndPoint Manager Version ".$this->global_cfg['version']; |
|---|
| | 1010 | |
|---|
| | 1011 | // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is |
|---|
| | 1012 | //Start timer |
|---|
| | 1013 | $time_start = microtime(true); |
|---|
| | 1014 | $returned_data = $provisioner_lib->generate_config(); |
|---|
| | 1015 | //End timer |
|---|
| | 1016 | $time_end = microtime(true); |
|---|
| | 1017 | $time = $time_end - $time_start; |
|---|
| | 1018 | if($time > 360) { |
|---|
| | 1019 | $this->error['generate_time'] = "It took an awfully long time to generate configs...(".round($time,2)." seconds)"; |
|---|
| | 1020 | } |
|---|
| | 1021 | //Create Directory Structure (If needed) |
|---|
| | 1022 | if(isset($provisioner_lib->directory_structure)) { |
|---|
| | 1023 | foreach($provisioner_lib->directory_structure as $data) { |
|---|
| | 1024 | $dir = $this->global_cfg['config_location'] . $data; |
|---|
| | 1025 | if(!file_exists($dir)) { |
|---|
| | 1026 | mkdir($dir, 0777); |
|---|
| | 1027 | } |
|---|
| | 1028 | } |
|---|
| | 1029 | } |
|---|
| | 1030 | |
|---|
| | 1031 | //Copy Files/Directories (If needed) |
|---|
| | 1032 | if(isset($provisioner_lib->copy_files)) { |
|---|
| | 1033 | foreach($provisioner_lib->copy_files as $data) { |
|---|
| | 1034 | if(((file_exists($this->global_cfg['config_location'].$data)) AND (!in_array($data,$provisioner_lib->protected_files))) OR (!file_exists($this->global_cfg['config_location'].$data))) { |
|---|
| | 1035 | if(is_dir(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data)) { |
|---|
| | 1036 | if(!file_exists($this->global_cfg['config_location'].$data)) { |
|---|
| | 1037 | if (!@mkdir($this->global_cfg['config_location'].$data, 0777)) { |
|---|
| | 1038 | $this->error['parse_configs'] = "Could Not Create Directory: ".$data; |
|---|
| | 1039 | return(FALSE); |
|---|
| | 1040 | } |
|---|
| | 1041 | } |
|---|
| | 1042 | $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/"); |
|---|
| | 1043 | $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); |
|---|
| | 1044 | // could use CHILD_FIRST if you so wish |
|---|
| | 1045 | foreach ($iterator as $file) { |
|---|
| | 1046 | if(is_dir($file)) { |
|---|
| | 1047 | $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); |
|---|
| | 1048 | if(!file_exists($this->global_cfg['config_location'].$data."/".$dir)) { |
|---|
| | 1049 | if (!@mkdir($this->global_cfg['config_location'].$data."/".$dir, 0777)) { |
|---|
| | 1050 | $this->error['parse_configs'] = "Could Not Create Directory: ".$data."/".$dir; |
|---|
| | 1051 | return(FALSE); |
|---|
| | 1052 | } |
|---|
| | 1053 | } |
|---|
| | 1054 | } else { |
|---|
| | 1055 | $dir = str_replace(PHONE_MODULES_PATH."endpoint/".$phone_info['directory']."/".$phone_info['cfg_dir']."/".$data."/", "", $file); |
|---|
| | 1056 | if(!@copy($file, $this->global_cfg['config_location'].$data."/".$dir)) { |
|---|
| | 1057 | $this->error['parse_configs'] = "Could Not Copy File: ".$data."/".$dir; |
|---|
| | 1058 | return(FALSE); |
|---|
| | 1059 | } else { |
|---|
| | 1060 | chmod($this->global_cfg['config_location'].$data."/".$dir, 0777); |
|---|
| | 1061 | } |
|---|
| 1620 | | |
|---|
| 1621 | | //TODO: combine these queries |
|---|
| 1622 | | |
|---|
| 1623 | | $sql = "SELECT * FROM endpointman_model_list WHERE id='".$model."'"; |
|---|
| 1624 | | |
|---|
| 1625 | | $model_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| 1626 | | |
|---|
| 1627 | | $sql = "SELECT * FROM endpointman_product_list WHERE id='".$model_row['product_id']."'"; |
|---|
| 1628 | | |
|---|
| 1629 | | $product_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| 1630 | | |
|---|
| 1631 | | $sql = "SELECT * FROM endpointman_brand_list WHERE id=".$model_row['brand']; |
|---|
| 1632 | | |
|---|
| 1633 | | |
|---|
| 1634 | | $brand_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| 1635 | | |
|---|
| 1636 | | $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/family_data.xml'); |
|---|
| 1637 | | |
|---|
| 1638 | | if($product_row['cfg_ver'] <= $family_line_xml['data']['version']) { |
|---|
| 1639 | | $key = $this->arraysearchrecursive($model_row['model'], $family_line_xml['data']['model_list'], 'model'); |
|---|
| 1640 | | |
|---|
| 1641 | | if($key === FALSE) { |
|---|
| 1642 | | $this->error['sync_model'] = "Can't locate model in family XML file"; |
|---|
| 1643 | | return(FALSE); |
|---|
| 1644 | | } else { |
|---|
| 1645 | | if(is_array($family_line_xml['data']['model_list'][$key[0]]['template_data']['files'])) { |
|---|
| 1646 | | $template_list = implode(",",$family_line_xml['data']['model_list'][$key[0]]['template_data']['files']); |
|---|
| 1647 | | $template_list_array = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 1640 | if((!empty($model)) OR ($model > 0)) { |
|---|
| | 1641 | $sql = "SELECT * FROM endpointman_model_list WHERE id='".$model."'"; |
|---|
| | 1642 | |
|---|
| | 1643 | $model_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 1644 | |
|---|
| | 1645 | $sql = "SELECT * FROM endpointman_product_list WHERE id='".$model_row['product_id']."'"; |
|---|
| | 1646 | |
|---|
| | 1647 | $product_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 1648 | |
|---|
| | 1649 | $sql = "SELECT * FROM endpointman_brand_list WHERE id=".$model_row['brand']; |
|---|
| | 1650 | |
|---|
| | 1651 | |
|---|
| | 1652 | $brand_row =& $this->db->getRow($sql, array(),DB_FETCHMODE_ASSOC); |
|---|
| | 1653 | |
|---|
| | 1654 | $family_line_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/family_data.xml'); |
|---|
| | 1655 | |
|---|
| | 1656 | if($product_row['cfg_ver'] <= $family_line_xml['data']['version']) { |
|---|
| | 1657 | $key = $this->arraysearchrecursive($model_row['model'], $family_line_xml['data']['model_list'], 'model'); |
|---|
| | 1658 | |
|---|
| | 1659 | if($key === FALSE) { |
|---|
| | 1660 | $this->error['sync_model'] = "Can't locate model in family XML file"; |
|---|
| | 1661 | return(FALSE); |
|---|
| 1649 | | $template_list = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| 1650 | | $template_list_array[0] = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| 1651 | | } |
|---|
| 1652 | | } |
|---|
| 1653 | | |
|---|
| 1654 | | $sql = "UPDATE endpointman_model_list SET max_lines = '".$family_line_xml['data']['model_list'][$key[0]]['lines']."', template_list = '".$template_list."' WHERE id = '".$model."'"; |
|---|
| 1655 | | $this->db->query($sql); |
|---|
| 1656 | | |
|---|
| 1657 | | $version = $family_line_xml['data']['version']; |
|---|
| 1658 | | $long_name = $family_line_xml['data']['name']; |
|---|
| 1659 | | $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); |
|---|
| 1660 | | $configuration_files = $family_line_xml['data']['configuration_files']; |
|---|
| 1661 | | |
|---|
| 1662 | | $sql = "UPDATE endpointman_product_list SET long_name = '".$template_list."', short_name = '".$short_name."' , cfg_ver = '".$version."', WHERE id = '".$product_row['id']."'"; |
|---|
| 1663 | | $this->db->query($sql); |
|---|
| 1664 | | |
|---|
| 1665 | | $template_data_array = array(); |
|---|
| 1666 | | foreach($template_list_array as $data) { |
|---|
| 1667 | | if(file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data)) { |
|---|
| 1668 | | $template_data_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data); |
|---|
| 1669 | | $template_data_xml = $this->fix_single_array_keys($template_data_xml['template_data']); |
|---|
| 1670 | | $template_data_array = array_merge($template_data_array, $template_data_xml); |
|---|
| 1671 | | } |
|---|
| 1672 | | } |
|---|
| 1673 | | |
|---|
| 1674 | | if (file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_custom.xml')) { |
|---|
| 1675 | | $template_data_multi = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_custom.xml'); |
|---|
| 1676 | | if($template_data_multi) { |
|---|
| 1677 | | $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); |
|---|
| 1678 | | $template_data_array = array_merge($template_data_array, $template_data_multi); |
|---|
| 1679 | | } |
|---|
| 1680 | | } |
|---|
| 1681 | | |
|---|
| 1682 | | if (file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_' . $model_row['model'] . '_custom.xml')) { |
|---|
| 1683 | | $template_data_multi = $this->xml2array(self::$modules_path . $this->brand_name . "/" . $this->family_line . "/template_data_" . $this->model . "_custom.xml"); |
|---|
| 1684 | | if($template_data_multi) { |
|---|
| 1685 | | $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); |
|---|
| 1686 | | $template_data_array = array_merge($template_data_array, $template_data_multi); |
|---|
| 1687 | | } |
|---|
| 1688 | | } |
|---|
| 1689 | | |
|---|
| 1690 | | if(empty($template_data_array)) { |
|---|
| 1691 | | $this->error['sync_model'] = "No Template Data Found"; |
|---|
| 1692 | | return(FALSE); |
|---|
| 1693 | | } |
|---|
| 1694 | | |
|---|
| 1695 | | $sql = "UPDATE endpointman_model_list SET template_data = '".serialize($template_data_array)."' WHERE id = '".$model."'"; |
|---|
| 1696 | | $this->db->query($sql); |
|---|
| 1697 | | } |
|---|
| 1698 | | |
|---|
| 1699 | | return(TRUE); |
|---|
| | 1663 | if(is_array($family_line_xml['data']['model_list'][$key[0]]['template_data']['files'])) { |
|---|
| | 1664 | $template_list = implode(",",$family_line_xml['data']['model_list'][$key[0]]['template_data']['files']); |
|---|
| | 1665 | $template_list_array = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 1666 | } else { |
|---|
| | 1667 | $template_list = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 1668 | $template_list_array[0] = $family_line_xml['data']['model_list'][$key[0]]['template_data']['files']; |
|---|
| | 1669 | } |
|---|
| | 1670 | } |
|---|
| | 1671 | |
|---|
| | 1672 | $sql = "UPDATE endpointman_model_list SET max_lines = '".$family_line_xml['data']['model_list'][$key[0]]['lines']."', template_list = '".$template_list."' WHERE id = '".$model."'"; |
|---|
| | 1673 | $this->db->query($sql); |
|---|
| | 1674 | |
|---|
| | 1675 | $version = $family_line_xml['data']['version']; |
|---|
| | 1676 | $long_name = $family_line_xml['data']['name']; |
|---|
| | 1677 | $short_name = preg_replace("/\[(.*?)\]/si", "", $family_line_xml['data']['name']); |
|---|
| | 1678 | $configuration_files = $family_line_xml['data']['configuration_files']; |
|---|
| | 1679 | |
|---|
| | 1680 | $sql = "UPDATE endpointman_product_list SET long_name = '".$template_list."', short_name = '".$short_name."' , cfg_ver = '".$version."', WHERE id = '".$product_row['id']."'"; |
|---|
| | 1681 | $this->db->query($sql); |
|---|
| | 1682 | |
|---|
| | 1683 | $template_data_array = array(); |
|---|
| | 1684 | foreach($template_list_array as $data) { |
|---|
| | 1685 | if(file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data)) { |
|---|
| | 1686 | $template_data_xml = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/'.$data); |
|---|
| | 1687 | $template_data_xml = $this->fix_single_array_keys($template_data_xml['template_data']); |
|---|
| | 1688 | $template_data_array = array_merge($template_data_array, $template_data_xml); |
|---|
| | 1689 | } |
|---|
| | 1690 | } |
|---|
| | 1691 | |
|---|
| | 1692 | if (file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_custom.xml')) { |
|---|
| | 1693 | $template_data_multi = $this->xml2array(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_custom.xml'); |
|---|
| | 1694 | if($template_data_multi) { |
|---|
| | 1695 | $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); |
|---|
| | 1696 | $template_data_array = array_merge($template_data_array, $template_data_multi); |
|---|
| | 1697 | } |
|---|
| | 1698 | } |
|---|
| | 1699 | |
|---|
| | 1700 | if (file_exists(PHONE_MODULES_PATH.'/endpoint/'.$brand_row['directory'].'/'.$product_row['cfg_dir'].'/template_data_' . $model_row['model'] . '_custom.xml')) { |
|---|
| | 1701 | $template_data_multi = $this->xml2array(self::$modules_path . $this->brand_name . "/" . $this->family_line . "/template_data_" . $this->model . "_custom.xml"); |
|---|
| | 1702 | if($template_data_multi) { |
|---|
| | 1703 | $template_data_multi = $this->fix_single_array_keys($template_data_multi['template_data']['item']); |
|---|
| | 1704 | $template_data_array = array_merge($template_data_array, $template_data_multi); |
|---|
| | 1705 | } |
|---|
| | 1706 | } |
|---|
| | 1707 | |
|---|
| | 1708 | if(empty($template_data_array)) { |
|---|
| | 1709 | $this->error['sync_model'] = "No Template Data Found"; |
|---|
| | 1710 | return(FALSE); |
|---|
| | 1711 | } |
|---|
| | 1712 | |
|---|
| | 1713 | $sql = "UPDATE endpointman_model_list SET template_data = '".serialize($template_data_array)."' WHERE id = '".$model."'"; |
|---|
| | 1714 | $this->db->query($sql); |
|---|
| | 1715 | } |
|---|
| | 1716 | |
|---|
| | 1717 | return(TRUE); |
|---|
| | 1718 | } else { |
|---|
| | 1719 | return(FALSE); |
|---|
| | 1720 | } |
|---|