Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: addon xml generation (WIP) #105

Draft
wants to merge 1 commit into
base: extension_mobility
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions Sccp_manager.inc/xmlinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function create_default_XML($store_path = '', $data_values = array(), $model_inf
$node->addAttribute('model', $var['vendor'] . ' ' . $var['model']);
}
}
$xml_work->asXml($xml_name); // Save XMLDefault1.cnf.xml
$this->saveXml($xml_work, $xml_name);
}
}

Expand Down Expand Up @@ -330,28 +330,23 @@ function create_SEP_XML($store_path = '', $data_values = array(), $dev_config =
$xml_work->$key = time();
break;
case 'loadinformation':
// Set Path Image ????
if (isset($dev_config["tftp_firmware"])) {
$xml_work->$key = (isset($dev_config["loadimage"])) ? $dev_config["tftp_firmware"] . $dev_config["loadimage"] : '';
} else {
$xml_work->$key = (isset($dev_config["loadimage"])) ? $dev_config["loadimage"] : '';
}
// $xml_work->$key = $dev_config["loadimage"];
if (!empty($dev_config['addon'])) {
$xnode = $xml_work->addChild('addOnModules');
$ti = 1;
$hw_addon = explode(',', $dev_config['addon']);
foreach ($hw_addon as $add_key) {
// foreach ($dev_config['addon_info'] as $add_key => $add_val) {
if (!empty($dev_config['addon_info'][$add_key])) {
$add_val = $dev_config['addon_info'][$add_key];
$xnode_obj = $xnode->addChild('addOnModule');
$xnode_obj->addAttribute('idx', $ti);
$xnode_obj->addChild('loadInformation', $add_val);
$ti++;
$hw_addon = explode(';', $dev_config['addon']);
foreach ($hw_addon as $inst => $key) {
$xnode_obj = $xnode->addChild('addOnModule');
$xnode_obj->addAttribute('idx', $inst + 1);
$loadinfo_key = $dev_config['addon'];
$loadinfo = $dev_config['addon_info'][$loadinfo_key];
if (!empty($loadinfo)) {
$xnode_obj->addChild('loadInformation', $loadinfo);
}
}
// $this->appendSimpleXmlNode($xml_work , $xnode_obj);
}
break;
case 'commonprofile':
Expand Down Expand Up @@ -401,9 +396,7 @@ function create_SEP_XML($store_path = '', $data_values = array(), $dev_config =
break;
}
}

// print_r($xml_work);
$xml_work->asXml($xml_name); // Save
$this->saveXml($xml_work, $xml_name);
} else {
die('Error Hardware template :' . $xml_template . ' not found');
}
Expand Down Expand Up @@ -743,17 +736,13 @@ function create_SEP_SIP_XML($store_path = '', $data_values = array(), $dev_confi
} else {
$xml_work->$key = (isset($dev_config["loadimage"])) ? $dev_config["loadimage"] : '';
}
// $xml_work->$key = $dev_config["loadimage"];
if (!empty($dev_config['addon'])) {
$xnode = $xml_work->addChild('addOnModules');
$ti = 1;
foreach ($dev_config['addon_info'] as $add_key => $add_val) {
$xnode_obj = $xnode->addChild('addOnModule');
$xnode_obj->addAttribute('idx', $ti);
$xnode_obj->addAttribute('idx', $add_key + 1);
$xnode_obj->addChild('loadInformation', $add_val);
$ti++;
}
// $this->appendSimpleXmlNode($xml_work , $xnode_obj);
}
break;
case 'commonProfile':
Expand Down Expand Up @@ -803,9 +792,7 @@ function create_SEP_SIP_XML($store_path = '', $data_values = array(), $dev_confi
break;
}
}

// print_r($xml_work);
$xml_work->asXml($xml_name); // Save
$this->saveXml($xml_work, $xml_name);
} else {
die('Error Hardware template :' . $xml_template . ' not found');
}
Expand Down Expand Up @@ -937,4 +924,13 @@ private function appendSimpleXmlNode($xml, $element = SimpleXMLElement)
// $dom->parentNode->appendChild($import, $dom);
$dom->parentNode->appendChild($import->cloneNode(true));
}

// temporary helper function to save xml with proper indentation
private function saveXml($xml, $filename) {
$dom = new \DOMDocument("1.0");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
$dom->save($filename);
}
}