Location: PHPKode > projects > Phpqadmin > phpqadmin-0.4/include/functions_company.php
<?php

function is_company($company)
{
	return is_dir(QMAIL_POP_DIR.DIR_SLASH.$company) && !in_array($company,array('.','..')) && $company != '';
}


function get_companies()
{
	$dir = opendir(QMAIL_POP_DIR);
	$companies = array();
	while(false !== ($file = readdir($dir)))
	{
		if (is_company($file))
		{
			array_push($companies,array('ID' => $file));
		}
	}
	@closedir($dir);
	return $companies;
}




function create_company($company,$password='')
{
	$new_dir = QMAIL_POP_DIR.DIR_SLASH.$company;
	if (!is_dir($new_dir))
	{
		mkdir($new_dir);
		set_company_password($company,$password);
		return true;
	}
    echo "chown dir: {$new_dir} to user:".QMAIL_USER."\n"; 
	//chown($new_dir,QMAIL_USER);
	//chgrp($new_dir,QMAIL_GROUP);
	chmod($new_dir,0777);
	return false;
}



function set_company_password($company,$password)
{
	$fp = fopen(QMAIL_POP_DIR.DIR_SLASH.$company.DIR_SLASH.'passwd','wb');
	fwrite($fp,generate_password($password));
	fclose($fp);
	return true;
}



function get_company_file($company,$filename)
{
	$filename = QMAIL_POP_DIR.DIR_SLASH.$company.DIR_SLASH.$filename;
	@chmod($filename,01666);
	$result = (false!== $fp = @fopen($filename,'rb'));
	if (!$result)
		return '';
	$contents = fread($fp,filesize($filename));
	fclose($fp);
	chmod($filename,0600);
	return $contents;
}

function set_company_file($company,$filename,$value)
{
	$filename = QMAIL_POP_DIR.DIR_SLASH.$company.DIR_SLASH.$filename;
	chmod($filename,01666);
	$fp = fopen($filename,'wb');
	fwrite($fp,$value);
	fclose($fp);
	chmod($filename,0600);
	return true;
}

function get_company_domains($company)
{
	return preg_split('/\s+/',get_company_file($company,'domains'),-1,PREG_SPLIT_NO_EMPTY);
}

function set_company_domains($company,$domains)
{
	return set_company_file($company,'domains',$domains);
}

?>
Return current item: Phpqadmin