public function fetchOne($params = array(), $hydrationMode = null)
 {
     $result = parent::fetchOne($params, $hydrationMode);
     $_p = $this->getParams($params);
     if ('exist' === $_p['where'][0]) {
         $tpl = new myTemplate();
         $tpl->fromArray(array('id' => 1, 'name' => 'exist', 'body' => 'exist', 'renderer' => 'php'));
         return $tpl;
     } elseif ('empty' === $_p['where'][0]) {
         $tpl = new myTemplate();
         $tpl->fromArray(array('id' => 1, 'name' => '', 'body' => '', 'renderer' => 'php'));
         return $tpl;
     }
     return $result;
 }
Beispiel #2
0
function genSWIP($ds, $baseindex, $start, $end, $cust, $descrip, $swipmod, $filename)
{
    global $ntnameopt;
    //************ now process customer standard fields ************//
    $result1 =& $ds->ds->Execute("SELECT *\n            FROM custinfo\n            WHERE customer={$cust}");
    // should only be one row here, none if SWIP turned off during creation
    // of customer
    $row1 = $result1->FetchRow();
    $result2 =& $ds->ds->Execute("SELECT hname, ipaddr\n            FROM revdns\n            WHERE customer={$cust}\n            ORDER BY horder");
    $fields = array();
    $fields["ntsnum"] = $start;
    $fields["ntenum"] = $end;
    $fields = array_merge($fields, $row1);
    // use subnet description field? then only a-z, 0-9 max 21 chars allowed
    if ($ntnameopt and preg_match("/^[A-Za-z0-9\\-]{1,21}\$/", $descrip)) {
        $ntname = $descrip;
    } else {
        $ntname = MAINTAINERID . "-" . str_replace(".", "-", $start);
    }
    $fields["ntname"] = $ntname;
    $fields["maint"] = MAINTAINERID;
    if ($row2 = $result2->FetchRow()) {
        $fields["hname1"] = $row2["hname"];
        $fields["ipaddr1"] = $row2["ipaddr"];
    } else {
        $fields["hname1"] = "";
        $fields["ipaddr1"] = "";
    }
    if ($row2 = $result2->FetchRow()) {
        $fields["hname2"] = $row2["hname"];
        $fields["ipaddr2"] = $row2["ipaddr"];
    } else {
        $fields["hname1"] = "";
        $fields["ipaddr1"] = "";
    }
    if ($row2 = $result2->FetchRow()) {
        $fields["hname3"] = $row2["hname"];
        $fields["ipaddr3"] = $row2["ipaddr"];
    } else {
        $fields["hname1"] = "";
        $fields["ipaddr1"] = "";
    }
    $cnt = 3;
    while ($row2 = $result2->FetchRow()) {
        $fields["hname{$cnt}"] = $row2["hname"];
        $fields["ipaddr{$cnt}"] = $row2["ipaddr"];
        $cnt++;
    }
    $fields["regid"] = REGID;
    $fields["password"] = REGPASS;
    $fields["source"] = REGISTRY;
    // add a UTC format date
    $now = getdate();
    $fields["date"] = $now["year"] . str_pad($now["mon"], 2, '0', STR_PAD_LEFT) . str_pad($now["mday"], 2, '0', STR_PAD_LEFT);
    $fields["swipmod"] = $swipmod;
    //************ now process customer template fields ************//
    // if a specific customer template exists
    $err = TRUE;
    $template = new IPplanIPTemplate("custtemplate", $cust);
    $err = $template->is_error();
    // process fields form the user defined template
    if (!$err) {
        $restmp =& $ds->ds->Execute("SELECT info\n                FROM custadd\n                WHERE customer={$cust}");
        if ($rowadd = $restmp->FetchRow()) {
            $template->Merge($template->decode($rowadd["info"]));
            foreach ($template->userfld as $key => $arr) {
                $fields[$key] = $arr["value"];
            }
        }
    }
    //************ now process base template fields ************//
    // if a specific base template exists, use that, else use generic template
    $err = TRUE;
    $template = new IPplanIPTemplate("basetemplate", $cust);
    $err = $template->is_error();
    if (!$err) {
        $result_template =& $ds->ds->Execute("SELECT info, infobin\n                FROM baseadd\n                WHERE baseindex={$baseindex}");
        if ($rowadd = $result_template->FetchRow()) {
            $template->Merge($template->decode($rowadd["info"]));
            foreach ($template->userfld as $key => $arr) {
                $fields[$key] = $arr["value"];
            }
        }
    }
    $rep = new myTemplate();
    if ($rep->get("../templates/{$filename}") == FALSE) {
        return FALSE;
    }
    $swip = $rep->process($fields);
    return $swip;
}