<?
/**
 * VoiceOne Webservices Methods
 *  
 * @package voiceone_webservices
 * @subpackage ast_stat
 */
//******************************************************************************
//******************           PUBLIC FUNCTIONS            *********************
//******************************************************************************

//******************************************************************************
//*****************           PRIVATE FUNCTIONS            *********************
//******************************************************************************
/**
* FUNCTION: writeAstStatConfFile
* write asterisk-stat us
* @param location:Location -> Structure contains location data
* @return:int -> If success it return location id, else return zero
*/
function ast_writeStatUsers(){
  global $voTools;
  //get access users
  $accessArr=array(); 
  $userArr=getUser(0);
  if(is_array($userArr)){
    foreach($userArr as $u){
      if($u["type"]!==USER_STANDARD){
        if(trim($u["username"])!=""){
          $accessArr[]=array(
              "username" => $u["username"],
              "password" => $u["password"]
            );
        }else{
          $client=getClient($u["entity_id"],0);
          if((is_array($client))&&(is_array($client[0]))){
            $accessArr[]=array(
              "username" => $client[0]["username"],
              "password" => $client[0]["password"]
            );
          }
        }
      }
    }
  }
  //clean all users from config file
  exec("sudo $voTools ast_cleanStatUsers",$output,$retScript);
  //insert users in config file
  if(is_array($accessArr)){
    foreach($accessArr as $a){
      $username=$a["username"];
      $password=$a["password"];
      exec("sudo $voTools ast_putStatUser $username $password",$output,$retScript);
    }
  }
  //return
	return 1;
}
?>