예제 #1
0
/**
*  save group record
*  @param	f			array		group record
*  @return	objResponse	object		xajax response object
*/
function save($f)
{
    global $locate, $db, $config;
    $objResponse = new xajaxResponse();
    //print_r($f);exit;
    if (trim($f['resellername']) == '') {
        $objResponse->addAlert($locate->Translate("please enter the resellername"));
        return $objResponse;
    }
    $f['creditlimit'] = trim($f['creditlimit']);
    if ($f['creditlimit'] == '' or !is_numeric($f['creditlimit'])) {
        $f['creditlimit'] = 0;
    }
    //print_r($f);exit;
    //	if($f['routetype'] == 'customize') {
    //		$f['trunkname'] = trim($f['trunkname']);
    //		if($f['trunkname'] == '') {
    //			$objResponse->addAlert($locate->Translate("please enter the trunkname"));
    //			return $objResponse;
    //		}
    //		$f['detail'] = trim($f['detail']);
    //		if($f['detail'] == '') {
    //			$objResponse->addAlert($locate->Translate("please enter the detail"));
    //			return $objResponse;
    //		}
    //		if(trim($f['timeout']) == '') {
    //			$f['timeout'] = 0;
    //		}
    //		$pin = Customer::generateUniquePin(10);
    //		$n = array('trunkname'=>$f['trunkname'],'trunkprotocol'=>$f['protocoltype'],'registrystring'=>$f['registrystring'],'detail'=>$f['detail'],'timeout'=>$f['timeout'],'trunkprefix'=>$f['trunkprefix'],'removeprefix'=>$f['removeprefix'],'trunkidentity'=>$pin);
    //		$resTrunk = Customer::insertNewTrunk($n);
    //		$f['trunk_id'] = $resTrunk;
    //	} else if($f['routetype'] == 'default') {
    //$f['trunk_id'] = -1;
    //	} else if($f['routetype'] == 'auto'){
    //$f['trunk_id'] = 0;
    //	}
    if ($f['trunk1_id'] != $f['tmptrunk1id'] && $f['tmptrunk1id'] > 0) {
        Customer::deleteRecord($f['tmptrunk1id'], 'trunks');
    }
    if ($f['trunk2_id'] != $f['tmptrunk2id'] && $f['tmptrunk2id'] > 0) {
        Customer::deleteRecord($f['tmptrunk2id'], 'trunks');
    }
    if ($config['synchronize']['id_autocrement_byset']) {
        $local_lastid = astercrm::getLocalLastId('resellergroup');
        $f['id'] = intval($local_lastid + 1);
    }
    $respOk = Customer::insertNewResellergroup($f);
    // add a new group
    if ($respOk) {
        $html = createGrid(0, ROWSXPAGE);
        $objResponse->addAssign("grid", "innerHTML", $html);
        $objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("Add Reseller"));
        $objResponse->addAssign("formDiv", "style.visibility", "hidden");
        $objResponse->addClear("formDiv", "innerHTML");
    } else {
        $objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("rec_cannot_insert"));
    }
    //generate include file
    if ($_SESSION['curuser']['usertype'] == 'admin') {
        astercc::generateResellerFile();
    }
    return $objResponse->getXML();
}