function?g(&$var,?$key,?$default?=?NULL){?#make?it?easy?to?develop?with?notices?on
????
return?isset($var[$key])???$var[$key]?:?$default;
}
function?
r($key){?return?g($_REQUEST,?$key);?}

function?
show($data,?$func?=?"print_r",?$return_str?=?false){
????
ob_start();
????
$func($data);
????
$output?=?'
'.htmlspecialchars(ob_get_contents()).'
'
;
????
ob_end_clean();
????if(
$return_str)?return?$output;?else?echo?$output;
}

function?
ob_clean_all?()?{
????
$ob_active?=?ob_get_length?()?!==?false;
????while(
$ob_active)?{
????????
ob_end_clean();
????????
$ob_active?=?ob_get_length?()?!==?false;
????}

????return?
true;
}

function?
generate_password?($length?=?8)?{
????
$password?=?'';

????
//?define?possible?characters
????
$possible?=?"0123456789bcdfghjkmnpqrstvwxyz!@#$%^&*(){}:,./;'[]";?

????for?(
$i?=?0;?$i?$length;?$i++)?{
????????
$char?=?substr($possible,?mt_rand(0,?strlen($possible)-1),?1);

????????
//?Uppercase?or?not?
????????
if?(mt_rand(0,1)?>?0)?{?$char?=?strtoupper($char);?}

????????
$password?.=?$char;
????}

????return?
$password;
}

function?
return_error?($msg,?$num=0)?{
????
ob_clean_all();

????
//?Create?JSON?response
????
$json?=?new?Services_JSON();
????
$error?=?array('error'?=>?array('msg'?=>?$msg,?'num'?=>?$num));
????
$error?=?$json->encode($error);

????echo?
$error;
????die();
}

function?
return_raw_json($val)?{
????
ob_clean_all();

????
//?Create?JSON?response
????
$json?=?new?Services_JSON();
????
$val_encoded?=?$json->encode($val);

????echo?
$val_encoded;
????die();
}

function?
json_queue_add?($func,?$args)?{
????
$funcs?=&?$GLOBALS['_json_queue'];

????
//?Add?to?commands?array
????
$funcs[]?=?array('func'?=>?$func,?'args'?=>?$args);
}

function?
json_queue_send?()?{
????
$funcs?=&?$GLOBALS['_json_queue'];
????
ob_clean_all();

????
$data?=?array('queue'?=>?$funcs);

????
return_raw_json($data);
}


?>