Add get_template_dir to the PHP class.

This commit is contained in:
Mark Crane 2014-02-22 23:20:55 +00:00
parent 87a79a9211
commit dd688d52a6
2 changed files with 69 additions and 9 deletions

View File

@ -422,22 +422,21 @@ require_once "resources/require.php";
echo " ".$text['label-device_template'].":\n"; echo " ".$text['label-device_template'].":\n";
echo "</td>\n"; echo "</td>\n";
echo "<td class='vtable' align='left'>\n"; echo "<td class='vtable' align='left'>\n";
$device = new device;
$template_dir = $device->get_template_dir();
echo "<select id='device_template' name='device_template' class='formfld'>\n"; echo "<select id='device_template' name='device_template' class='formfld'>\n";
echo "<option value=''></option>\n"; echo "<option value=''></option>\n";
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/".$_SESSION["domain_name"])) {
$temp_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/".$_SESSION["domain_name"]; if ($dh = opendir($template_dir)) {
} else {
$temp_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision";
}
if($dh = opendir($temp_dir)) {
while($dir = readdir($dh)) { while($dir = readdir($dh)) {
if($file != "." && $dir != ".." && $dir[0] != '.') { if($file != "." && $dir != ".." && $dir[0] != '.') {
if(is_dir($temp_dir . "/" . $dir)) { if(is_dir($template_dir . "/" . $dir)) {
echo "<optgroup label='$dir'>"; echo "<optgroup label='$dir'>";
if($dh_sub = opendir($temp_dir.'/'.$dir)) { if($dh_sub = opendir($template_dir.'/'.$dir)) {
while($dir_sub = readdir($dh_sub)) { while($dir_sub = readdir($dh_sub)) {
if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') { if($file_sub != '.' && $dir_sub != '..' && $dir_sub[0] != '.') {
if(is_dir($temp_dir . '/' . $dir .'/'. $dir_sub)) { if(is_dir($template_dir . '/' . $dir .'/'. $dir_sub)) {
if ($device_template == $dir."/".$dir_sub) { if ($device_template == $dir."/".$dir_sub) {
echo "<option value='".$dir."/".$dir_sub."' selected='selected'>".$dir."/".$dir_sub."</option>\n"; echo "<option value='".$dir."/".$dir_sub."' selected='selected'>".$dir."/".$dir_sub."</option>\n";
} }

View File

@ -29,6 +29,7 @@ include "root.php";
class device { class device {
public $db; public $db;
public $domain_uuid; public $domain_uuid;
public $template_dir;
public function __construct() { public function __construct() {
//require_once "resources/classes/database.php"; //require_once "resources/classes/database.php";
@ -106,6 +107,66 @@ include "root.php";
return $device_vendor; return $device_vendor;
} }
public function get_template_dir() {
//set the default template directory
switch (PHP_OS) {
case "Linux":
//set the default template dir
if (strlen($this->template_dir) == 0) {
if (file_exists('/etc/fusionpbx/templates/provision')) {
$this->template_dir = '/etc/fusionpbx/templates/provision';
}
else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
}
break;
case "FreeBSD":
//if the FreeBSD port is installed use the following paths by default.
if (file_exists('/usr/local/etc/fusionpbx/templates/provision')) {
if (strlen($this->template_dir) == 0) {
$this->template_dir = '/usr/local/etc/fusionpbx/templates/provision';
}
else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
}
else {
if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
else {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
}
break;
case "NetBSD":
//set the default template_dir
if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
break;
case "OpenBSD":
//set the default template_dir
if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
break;
default:
//set the default template_dir
if (strlen($this->template_dir) == 0) {
$this->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/provision';
}
}
//check to see if the domain name sub directory exists
if (is_dir($this->template_dir."/".$_SESSION["domain_name"])) {
$this->template_dir = $this->template_dir."/".$_SESSION["domain_name"];
}
//return the template directory
return $this->template_dir;
}
} }
?> ?>