diff --git a/app/provision/resources/classes/provision.php b/app/provision/resources/classes/provision.php index 9cf76e08d1..b42789177c 100644 --- a/app/provision/resources/classes/provision.php +++ b/app/provision/resources/classes/provision.php @@ -196,40 +196,42 @@ include "root.php"; $user_contacts = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($prep_statement, $sql); - foreach ($user_contacts as &$row) { - $uuid = $row['contact_uuid']; - $phone_label = strtolower($row['phone_label']); - $contact_category = strtolower($row['contact_category']); + if (is_array($user_contacts)) { + foreach ($user_contacts as &$row) { + $uuid = $row['contact_uuid']; + $phone_label = strtolower($row['phone_label']); + $contact_category = strtolower($row['contact_category']); - $contact = array(); - $contacts[] = &$contact; - $contact['category'] = $is_group ? 'groups' : 'users'; - $contact['contact_uuid'] = $row['contact_uuid']; - $contact['contact_type'] = $row['contact_type']; - $contact['contact_category'] = $row['contact_category']; - $contact['contact_organization'] = $row['contact_organization']; - $contact['contact_name_given'] = $row['contact_name_given']; - $contact['contact_name_family'] = $row['contact_name_family']; - $contact['numbers'] = array(); + $contact = array(); + $contacts[] = &$contact; + $contact['category'] = $is_group ? 'groups' : 'users'; + $contact['contact_uuid'] = $row['contact_uuid']; + $contact['contact_type'] = $row['contact_type']; + $contact['contact_category'] = $row['contact_category']; + $contact['contact_organization'] = $row['contact_organization']; + $contact['contact_name_given'] = $row['contact_name_given']; + $contact['contact_name_family'] = $row['contact_name_family']; + $contact['numbers'] = array(); - $numbers = &$contact['numbers']; + $numbers = &$contact['numbers']; - if (($row['phone_primary'] == '1') || (!isset($contact['phone_number']))) { - $contact['phone_label'] = $phone_label; - $contact['phone_number'] = $row['phone_number']; - $contact['phone_extension'] = $row['phone_extension']; + if (($row['phone_primary'] == '1') || (!isset($contact['phone_number']))) { + $contact['phone_label'] = $phone_label; + $contact['phone_number'] = $row['phone_number']; + $contact['phone_extension'] = $row['phone_extension']; + } + + $numbers[] = array( + line_number => $line['line_number'], + phone_label => $phone_label, + phone_number => $row['phone_number'], + phone_extension => $row['phone_extension'], + phone_primary => $row['phone_primary'], + ); + + $contact['phone_number_' . $phone_label] = $row['phone_number']; + unset($contact, $numbers, $uuid, $phone_label); } - - $numbers[] = array( - line_number => $line['line_number'], - phone_label => $phone_label, - phone_number => $row['phone_number'], - phone_extension => $row['phone_extension'], - phone_primary => $row['phone_primary'], - ); - - $contact['phone_number_' . $phone_label] = $row['phone_number']; - unset($contact, $numbers, $uuid, $phone_label); } } @@ -278,13 +280,15 @@ include "root.php"; //build the provision array $provision = Array(); - foreach($_SESSION['provision'] as $key=>$val) { - if (strlen($val['var']) > 0) { $value = $val['var']; } - if (strlen($val['text']) > 0) { $value = $val['text']; } - if (strlen($val['boolean']) > 0) { $value = $val['boolean']; } - if (strlen($val['numeric']) > 0) { $value = $val['numeric']; } - if (strlen($value) > 0) { $provision[$key] = $value; } - unset($value); + if (is_array($_SESSION['provision'])) { + foreach($_SESSION['provision'] as $key=>$val) { + if (strlen($val['var']) > 0) { $value = $val['var']; } + if (strlen($val['text']) > 0) { $value = $val['text']; } + if (strlen($val['boolean']) > 0) { $value = $val['boolean']; } + if (strlen($val['numeric']) > 0) { $value = $val['numeric']; } + if (strlen($value) > 0) { $provision[$key] = $value; } + unset($value); + } } //check to see if the mac_address exists in devices @@ -483,10 +487,12 @@ include "root.php"; $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); - foreach($result as $row) { - $key = $row['device_setting_subcategory']; - $value = $row['device_setting_value']; - $provision[$key] = $value; + if (is_array($result)) { + foreach($result as $row) { + $key = $row['device_setting_subcategory']; + $value = $row['device_setting_value']; + $provision[$key] = $value; + } } unset ($prep_statement); } @@ -500,10 +506,12 @@ include "root.php"; $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); - foreach($result as $row) { - $key = $row['device_setting_subcategory']; - $value = $row['device_setting_value']; - $provision[$key] = $value; + if (is_array($result)) { + foreach($result as $row) { + $key = $row['device_setting_subcategory']; + $value = $row['device_setting_value']; + $provision[$key] = $value; + } } unset ($prep_statement); } @@ -537,65 +545,67 @@ include "root.php"; //assign the keys array $view->assign("lines", $device_lines); //set the variables - foreach($device_lines as $row) { - //set the variables - $line_number = $row['line_number']; - $register_expires = $row['register_expires']; - $sip_transport = strtolower($row['sip_transport']); - $sip_port = $row['sip_port']; + if (is_array($device_lines)) { + foreach($device_lines as $row) { + //set the variables + $line_number = $row['line_number']; + $register_expires = $row['register_expires']; + $sip_transport = strtolower($row['sip_transport']); + $sip_port = $row['sip_port']; - //set defaults - if (strlen($register_expires) == 0) { $register_expires = "120"; } - if (strlen($sip_transport) == 0) { $sip_transport = "tcp"; } - if (strlen($sip_port) == 0) { - if ($line_number == "" || $line_number == "1") { - $sip_port = "5060"; + //set defaults + if (strlen($register_expires) == 0) { $register_expires = "120"; } + if (strlen($sip_transport) == 0) { $sip_transport = "tcp"; } + if (strlen($sip_port) == 0) { + if ($line_number == "" || $line_number == "1") { + $sip_port = "5060"; + } + else { + $sip_port = "506".($line_number + 1); + } } - else { - $sip_port = "506".($line_number + 1); + + //set a lines array index is the line number + $lines[$line_number]['register_expires'] = $register_expires; + $lines[$line_number]['sip_transport'] = strtolower($sip_transport); + $lines[$line_number]['sip_port'] = $sip_port; + $lines[$line_number]['server_address'] = $row["server_address"]; + $lines[$line_number]['outbound_proxy'] = $row["outbound_proxy_primary"]; + $lines[$line_number]['outbound_proxy_primary'] = $row["outbound_proxy_primary"]; + $lines[$line_number]['outbound_proxy_secondary'] = $row["outbound_proxy_secondary"]; + $lines[$line_number]['display_name'] = $row["display_name"]; + $lines[$line_number]['auth_id'] = $row["auth_id"]; + $lines[$line_number]['user_id'] = $row["user_id"]; + $lines[$line_number]['password'] = $row["password"]; + + //assign the variables for line one - short name + if ($line_number == "1") { + $view->assign("server_address", $row["server_address"]); + $view->assign("outbound_proxy", $row["outbound_proxy_primary"]); + $view->assign("outbound_proxy_primary", $row["outbound_proxy_primary"]); + $view->assign("outbound_proxy_secondary", $row["outbound_proxy_secondary"]); + $view->assign("display_name", $row["display_name"]); + $view->assign("auth_id", $row["auth_id"]); + $view->assign("user_id", $row["user_id"]); + $view->assign("user_password", $row["password"]); + $view->assign("sip_transport", $sip_transport); + $view->assign("sip_port", $sip_port); + $view->assign("register_expires", $register_expires); } - } - //set a lines array index is the line number - $lines[$line_number]['register_expires'] = $register_expires; - $lines[$line_number]['sip_transport'] = strtolower($sip_transport); - $lines[$line_number]['sip_port'] = $sip_port; - $lines[$line_number]['server_address'] = $row["server_address"]; - $lines[$line_number]['outbound_proxy'] = $row["outbound_proxy_primary"]; - $lines[$line_number]['outbound_proxy_primary'] = $row["outbound_proxy_primary"]; - $lines[$line_number]['outbound_proxy_secondary'] = $row["outbound_proxy_secondary"]; - $lines[$line_number]['display_name'] = $row["display_name"]; - $lines[$line_number]['auth_id'] = $row["auth_id"]; - $lines[$line_number]['user_id'] = $row["user_id"]; - $lines[$line_number]['password'] = $row["password"]; - - //assign the variables for line one - short name - if ($line_number == "1") { - $view->assign("server_address", $row["server_address"]); - $view->assign("outbound_proxy", $row["outbound_proxy_primary"]); - $view->assign("outbound_proxy_primary", $row["outbound_proxy_primary"]); - $view->assign("outbound_proxy_secondary", $row["outbound_proxy_secondary"]); - $view->assign("display_name", $row["display_name"]); - $view->assign("auth_id", $row["auth_id"]); - $view->assign("user_id", $row["user_id"]); - $view->assign("user_password", $row["password"]); - $view->assign("sip_transport", $sip_transport); - $view->assign("sip_port", $sip_port); - $view->assign("register_expires", $register_expires); - } - - //assign the variables with the line number as part of the name - $view->assign("server_address_".$line_number, $row["server_address"]); - $view->assign("outbound_proxy_".$line_number, $row["outbound_proxy_primary"]); - $view->assign("outbound_proxy_primary_".$line_number, $row["outbound_proxy_primary"]); - $view->assign("outbound_proxy_secondary_".$line_number, $row["outbound_proxy_secondary"]); - $view->assign("display_name_".$line_number, $row["display_name"]); - $view->assign("auth_id_".$line_number, $row["auth_id"]); - $view->assign("user_id_".$line_number, $row["user_id"]); - $view->assign("user_password_".$line_number, $row["password"]); - $view->assign("sip_transport_".$line_number, $sip_transport); - $view->assign("sip_port_".$line_number, $sip_port); - $view->assign("register_expires_".$line_number, $register_expires); + //assign the variables with the line number as part of the name + $view->assign("server_address_".$line_number, $row["server_address"]); + $view->assign("outbound_proxy_".$line_number, $row["outbound_proxy_primary"]); + $view->assign("outbound_proxy_primary_".$line_number, $row["outbound_proxy_primary"]); + $view->assign("outbound_proxy_secondary_".$line_number, $row["outbound_proxy_secondary"]); + $view->assign("display_name_".$line_number, $row["display_name"]); + $view->assign("auth_id_".$line_number, $row["auth_id"]); + $view->assign("user_id_".$line_number, $row["user_id"]); + $view->assign("user_password_".$line_number, $row["password"]); + $view->assign("sip_transport_".$line_number, $sip_transport); + $view->assign("sip_port_".$line_number, $sip_port); + $view->assign("register_expires_".$line_number, $register_expires); + } } unset ($prep_statement); } @@ -627,33 +637,35 @@ include "root.php"; if ($prep_statement) { $prep_statement->execute(); $extensions = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($extensions as $row) { - //get the contact_uuid - $uuid = $row['contact_uuid']; - //get the names - if (strlen($row['directory_full_name']) > 0) { - $name_array = explode(" ", $row['directory_full_name']); - } else { - $name_array = explode(" ", $row['effective_caller_id_name']); - } - $contact_name_given = array_shift($name_array); - $contact_name_family = trim(implode(' ', $name_array)); - //get the phone_extension - if (is_numeric($row['extension'])) { - $phone_extension = $row['extension']; - } - else { - $phone_extension = $row['number_alias']; - } - //save the contact array values - $contacts[$uuid]['category'] = 'extensions'; - $contacts[$uuid]['contact_uuid'] = $row['contact_uuid']; - $contacts[$uuid]['contact_category'] = 'extensions'; - $contacts[$uuid]['contact_name_given'] = $contact_name_given; - $contacts[$uuid]['contact_name_family'] = $contact_name_family; - $contacts[$uuid]['phone_extension'] = $phone_extension; - //unset the variables - unset($name_array, $contact_name_given, $contact_name_family, $phone_extension); + if (is_array($extensions)) { + foreach ($extensions as $row) { + //get the contact_uuid + $uuid = $row['contact_uuid']; + //get the names + if (strlen($row['directory_full_name']) > 0) { + $name_array = explode(" ", $row['directory_full_name']); + } else { + $name_array = explode(" ", $row['effective_caller_id_name']); + } + $contact_name_given = array_shift($name_array); + $contact_name_family = trim(implode(' ', $name_array)); + //get the phone_extension + if (is_numeric($row['extension'])) { + $phone_extension = $row['extension']; + } + else { + $phone_extension = $row['number_alias']; + } + //save the contact array values + $contacts[$uuid]['category'] = 'extensions'; + $contacts[$uuid]['contact_uuid'] = $row['contact_uuid']; + $contacts[$uuid]['contact_category'] = 'extensions'; + $contacts[$uuid]['contact_name_given'] = $contact_name_given; + $contacts[$uuid]['contact_name_family'] = $contact_name_family; + $contacts[$uuid]['phone_extension'] = $phone_extension; + //unset the variables + unset($name_array, $contact_name_given, $contact_name_family, $phone_extension); + } } } } @@ -701,27 +713,29 @@ include "root.php"; $keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); //override profile keys with device keys - foreach($keys as $row) { - //set the variables - $id = $row['device_key_id']; - $category = $row['device_key_category']; - - //build the device keys array - $device_keys[$category][$id] = $row; - if (is_uuid($row['device_profile_uuid'])) { - $device_keys[$category][$id]['device_key_owner'] = "profile"; - } - else { - $device_keys[$category][$id]['device_key_owner'] = "device"; - } - - //kept temporarily for backwards comptability to allow custom templates to be updated - $device_keys[$id] = $row; - if (is_uuid($row['device_profile_uuid'])) { - $device_keys[$id]['device_key_owner'] = "profile"; - } - else { - $device_keys[$id]['device_key_owner'] = "device"; + if (is_array($keys)) { + foreach($keys as $row) { + //set the variables + $id = $row['device_key_id']; + $category = $row['device_key_category']; + + //build the device keys array + $device_keys[$category][$id] = $row; + if (is_uuid($row['device_profile_uuid'])) { + $device_keys[$category][$id]['device_key_owner'] = "profile"; + } + else { + $device_keys[$category][$id]['device_key_owner'] = "device"; + } + + //kept temporarily for backwards comptability to allow custom templates to be updated + $device_keys[$id] = $row; + if (is_uuid($row['device_profile_uuid'])) { + $device_keys[$id]['device_key_owner'] = "profile"; + } + else { + $device_keys[$id]['device_key_owner'] = "device"; + } } } unset($keys); @@ -900,8 +914,10 @@ include "root.php"; } //replace the dynamic provision variables that are defined in default, domain, and device settings - foreach($provision as $key=>$val) { - $view->assign($key, $val); + if (is_array($provision)) { + foreach($provision as $key=>$val) { + $view->assign($key, $val); + } } //set the template directory @@ -965,13 +981,15 @@ include "root.php"; function write() { //build the provision array $provision = Array(); - foreach($_SESSION['provision'] as $key=>$val) { - if (strlen($val['var']) > 0) { $value = $val['var']; } - if (strlen($val['text']) > 0) { $value = $val['text']; } - if (strlen($val['boolean']) > 0) { $value = $val['boolean']; } - if (strlen($val['numeric']) > 0) { $value = $val['numeric']; } - if (strlen($value) > 0) { $provision[$key] = $value; } - unset($value); + if (is_array($_SESSION['provision'])) { + foreach($_SESSION['provision'] as $key=>$val) { + if (strlen($val['var']) > 0) { $value = $val['var']; } + if (strlen($val['text']) > 0) { $value = $val['text']; } + if (strlen($val['boolean']) > 0) { $value = $val['boolean']; } + if (strlen($val['numeric']) > 0) { $value = $val['numeric']; } + if (strlen($value) > 0) { $provision[$key] = $value; } + unset($value); + } } //check either we have destination path to write files @@ -988,7 +1006,7 @@ include "root.php"; unset ($prep_statement); //process each device - foreach ($result as &$row) { + if (is_array($result)) foreach ($result as &$row) { //get the values from the database and set as variables $domain_uuid = $row["domain_uuid"]; $device_uuid = $row["device_uuid"]; @@ -1028,7 +1046,7 @@ include "root.php"; } //loop through the provision templates - foreach ($dir_array as &$template_path) { + if (is_array($dir_array)) foreach ($dir_array as &$template_path) { if (is_dir($template_path)) continue; if (!file_exists($template_path)) continue; @@ -1048,7 +1066,7 @@ include "root.php"; //render and write configuration to file $provision_dir_array = explode(";", $provision["path"]); - foreach($provision_dir_array as $directory) { + if (is_array($provision_dir_array)) foreach($provision_dir_array as $directory) { //destinatino file path $dest_path = path_join($directory, $file_name);