PHP Code:
<!-- Mian PHP Script --!>
<?php
require_once("../sitemanager/includes/configure.php");
require_once("session_check.php");
require_once('../sitemanager/cPanel.php');
//echo $servername;
$domainerror_messageaftrpost ="";
$logindetailserror_messageaftrpost="";
$MaxfilesAllowed = 10;
$MaxemailsAllowed = 5;
if(isset($_POST['hdn_mode']))
{
$mode = trim($_POST['hdn_mode']);
$CusId = trim($_POST['hdn_userid']);
$UsrSubDomainName = str_replace(" ", "", addslashes(stripslashes(trim($_POST['txtbx_domainname']))) );
$UsrName = addslashes(stripslashes(trim($_POST['txtbx_UsrName'])));
$UsrPass = addslashes(stripslashes(trim($_POST['txtbx_UsrPass'])));
$DomainStatus = trim($_POST['hdn_DomainStatus']);
$UpdatedDate=date("Y-m-d H:i:s");
if($mode=="create")
{
$query="select * from crcustomers where customerid<>".$CusId." AND subdomain='".$UsrSubDomainName."'";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
$FldrNameToInsrt= str_replace("/","",$UsrSubDomainName);
//Create subdomain
if(RUNNING_ON=="local")
{
$FldrName =$_SERVER['DOCUMENT_ROOT']."/coconutregister/".$FldrNameToInsrt;
if(is_dir($FldrName))
{
$DomainalreadyExist=true;
}
else
{
$DomainalreadyExist=false;
}
}
else
{
//$ObjcPanel = new cPanel(SITENAMEONLY,CPANEL_USRNAME,CPANEL_PASS, 2082, false,'x');
//get sub domain list
//$arrsubDomains=$ObjcPanel->listSubdomains();
//check if the sub domain is already exist or not
//$subDomainForChkduplicate =$FldrNameToInsrt.".".SITENAMEONLY;
$DomainalreadyExist = is_dir("../".$FldrNameToInsrt) ; //in_array($subDomainForChkduplicate,$arrsubDomains);
}
if($numrows > 0 || $DomainalreadyExist!=false)
{
$domainerror_messageaftrpost="The subdomain you have choosen already exists. Please try entering another subdomain.";
}
else
{
//get default theme details
$Themequery="SELECT * from site_themes where set_default='Y' ";
$Themeresult = mysql_query($Themequery);
$Thmnumofrows = mysql_num_rows($Themeresult);
if($Thmnumofrows>0)
{
$Thmrow = mysql_fetch_array($Themeresult);
$db_ThemeId=$Thmrow["theme_id"];
$db_ThemeTitle=stripslashes($Thmrow["title"]);
$SelectedThmImg = stripslashes($Thmrow["image"]);
$filecontents= stripslashes($Thmrow["contents"]);
//remove html tags
$filecontents = eregi_replace("<html>","",$filecontents);
$filecontents = eregi_replace("</html>","",$filecontents);
$filecontents = eregi_replace("<title>","",$filecontents);
$filecontents = eregi_replace("</title>","",$filecontents);
$baseurlTag="<BASE href=\"http://www.cbt.cc\">";
$PageTitle="New Website from Island Yellow Pages.";
$filecontents= "<html><title>".$PageTitletoEdit."</title>".$baseurlTag.$filecontents."</html>";
}
else
{
$filecontents="<html><body><table valign='center' width=\"95%\"><tr><td> </td></tr><tr><td align='center'><font size='6'>This site is under construction. Please check back soon.</font></td></tr></table></body></html>";
//$FldrNameToInsrt= str_replace("/","",$UsrSubDomainName);
//$FldrName = "../sitemanager/".str_replace("/","",$UsrSubDomainName);
}
//Create subdomain
if(RUNNING_ON=="local")
{
// $FldrName =$_SERVER['DOCUMENT_ROOT']."/coconutregister/".$FldrNameToInsrt;
// if(!is_dir($FldrName))
mkdir($FldrName,0777);
//for index.php file
$phpfilecontents = "<?php require_once('C:\inetpub\wwwrootcoconutregister\sitemanager\domains_index.php'); ?>";
}
else
{
$FldrName =$_SERVER['DOCUMENT_ROOT']."/".$FldrNameToInsrt;
$ObjcPanel = new Domain(SITENAMEONLY,CPANEL_USRNAME,CPANEL_PASS, 2086, false,'x',"cbt.cc");
//get sub domain list
$arrsubDomains=$ObjcPanel->listSubdomains();
//check if the sub domain is already exist or not
$DomainalreadyExist =in_array($FldrNameToInsrt,$arrsubDomains);
if($DomainalreadyExist==false)
{
$DomainCreated = $ObjcPanel->addSubdomain($FldrNameToInsrt);
//for index.php file
$phpfilecontents = "<?php require_once('/home/cbtcc/public_html/sitemanager/domains_index.php'); ?>";
}
}
if($DomainalreadyExist==false)
{
$filename = "index.html";
//function used to write the contents in write mode starts
if(!is_file($FldrName."/".$filename))
{
//change mode
if(RUNNING_ON!="local")
{
chmod_11oo10($FldrNameToInsrt,777);
//for index.html file
filewrite_writemode($FldrName."/".$filename,stripslashes(trim($filecontents)));
//for index.php file
filewrite_writemode($FldrName."/index.php",trim($phpfilecontents));
}
//change mode
if(RUNNING_ON!="local")
{
chmod_11oo10($FldrNameToInsrt,755);
}
}
//check if the customer already having a domain or not
$Countquery="select count(*) as count from crcustomers where customerid=".$CusId;
$CusCount= fun_getMaxValue($Countquery,"count");
if($CusCount>0)
{
$update_query="UPDATE crcustomers SET ";
$update_query.="subdomain='".$UsrSubDomainName."',";
$update_query.="foldername='".$FldrNameToInsrt."',";
$update_query.="maxfilesallowed=$MaxfilesAllowed,";
$update_query.="disabled='no'";
$update_query.=" WHERE customerid=".$CusId;
$update_result=mysql_query($update_query);
}
else
{
//insert the domain name into the db
$insertquery="insert into crcustomers(customerid,subdomain,foldername,maxfilesallowed,maxemails_allowed,disabled,web_offline,lastupdated_date_forfiles) values($CusId,'$UsrSubDomainName','$FldrNameToInsrt',$MaxfilesAllowed,$MaxemailsAllowed,'no','no','$UpdatedDate')";
mysql_query($insertquery);
//insert the file name into the db
$insertquery="insert into user_files(user_id,filename,lastupdate) values($CusId,'$filename','$UpdatedDate')";
mysql_query($insertquery);
//get the count of files
$fileCountQry = "select count(*) as count from user_files where user_id=$CusId";
$fileCount = fun_getMaxValue($fileCountQry,"count");
//update the count with crcustomers table
$updatecount_query="UPDATE crcustomers SET ";
$updatecount_query.="numfilesused=".$fileCount;
$updatecount_query.=" WHERE customerid=".$CusId;
mysql_query($updatecount_query);
}
header("Location: createdomain.php?custid=$CusId&processmode=".$mode);
exit;
}
}
}
else if($mode=="change")
{
$CusCountQry = "select count(*) as count from crcustomers where customerid<>".$CusId." AND username='".$UsrName."'";
$CusCount = fun_getMaxValue($CusCountQry,"count");
if($CusCount > 0)
{
$logindetailserror_messageaftrpost="The username you have choosen is already exists. Please try to entering another username.";
}
else
{
//check if the customer already having a domain or not
$Countquery="select count(*) as count from crcustomers where customerid=".$CusId;
$CusCount= fun_getMaxValue($Countquery,"count");
if($CusCount>0)
{
$update_query="UPDATE crcustomers SET ";
$update_query.="username='".$UsrName."',";
$update_query.="password='".$UsrPass."' ";
$update_query.=" WHERE customerid=".$CusId;
$update_result=mysql_query($update_query);
}
else
{
///insert the domain name into the db
$insertquery="insert into crcustomers(customerid,username,password) values($CusId,'$UsrName','$UsrPass')";
mysql_query($insertquery);
}
header("Location: createdomain.php?custid=$CusId&processmode=".$mode);
exit;
}
}
else if($mode=="changedomainstatus")
{
//get users domain name
$ArrUsrdomaindetails=funGetFolderName($CusId);
//for set permissions