public function PerformAction()
 {
     if ($this->action != $this->action_do) {
         return;
     }
     $dbg_elem = new DbgElem();
     $dbhandle = $this->a2billing->DBHandle();
     if ($this->FG_DEBUG) {
         $this->pre_elem =& $dbg_elem;
     }
     $query = str_aldbparams($dbhandle, $this->QueryString, $this->_dirty_vars);
     if (strlen($query) < 1) {
         $this->pre_elem = new ErrorElem("Cannot update, internal error");
         $dbg_elem->content .= "Action: no query!\n";
     }
     $dbg_elem->content .= $query . "\n";
     $res = $dbhandle->Execute($query);
     if (!$res) {
         $this->action = $this->action_fail;
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         // 			throw new Exception( $err_str);
     } elseif ($this->expectRows && $dbhandle->Affected_Rows() < 1) {
         // No result rows: update clause didn't match
         $dbg_elem->content .= ".. EOF, no rows!\n";
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         $dbg_elem->obj = $dbhandle->Affected_Rows();
         $this->action = $this->action_fail;
     } else {
         $dbg_elem->content .= "Success: Rows: " . $dbhandle->Affected_Rows() . "\n";
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         $this->action = $this->action_success;
         $this->qryres =& $res;
     }
 }
 public function PerformAction()
 {
     global $PAGE_ELEMS;
     $this->verifyRights();
     if ($this->action != 'true') {
         return;
     }
     $dbg_elem = new DbgElem();
     $dbhandle = $this->a2billing->DBHandle();
     if ($this->FG_DEBUG > 0) {
         array_unshift($this->pre_elems, $dbg_elem);
     }
     $query = str_aldbparams($dbhandle, $this->QueryString, $this->_dirty_vars);
     if (strlen($query) < 1) {
         $this->pre_elems[] = new ErrorElem("Cannot update, internal error");
         $dbg_elem->content .= "Action: no query!\n";
     }
     $dbg_elem->content .= $query . "\n";
     $res = $dbhandle->Execute($query);
     if (!$res) {
         $this->action = 'ask';
         $this->pre_elems[] = new ErrorElem(str_params($this->failureString, array(_("database error")), 1));
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         // 			throw new Exception( $err_str);
     } elseif ($this->expectRows && $res->EOF && $dbhandle->Affected_Rows() < 1) {
         // No result rows: update clause didn't match
         $dbg_elem->content .= ".. EOF, no rows!\n";
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         $dbg_elem->content .= $dbhandle->NoticeMsg() . "\n";
         $dbg_elem->obj = $dbhandle->Affected_Rows();
         $this->pre_elems[] = new ErrorElem(str_params($this->failureString, array(_("no rows")), 1));
         $this->action = 'ask';
     } else {
         $dbg_elem->content .= "Success: Rows: " . $dbhandle->Affected_Rows() . "\n";
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         $dbg_elem->content .= $dbhandle->NoticeMsg() . "\n";
         if (strlen($this->successString)) {
             $this->pre_elems[] = new StringElem(str_params($this->successString, array($dbhandle->Affected_Rows()), 1));
         }
         $this->action = 'display';
         $this->qryres =& $res;
     }
 }
示例#3
0
 public function PerformAction()
 {
     global $PAGE_ELEMS;
     $this->verifyRights();
     if ($this->action != 'true') {
         return;
     }
     $dbg_elem = new DbgElem();
     $dbhandle = $this->a2billing->DBHandle();
     if ($this->FG_DEBUG > 0) {
         array_unshift($this->pre_elems, $dbg_elem);
     }
     if ($this->getpost_single('reset') == 't') {
         $query = str_aldbparams($dbhandle, "SELECT cc_a2b_server.id AS srvid, \n\t\t\t\tsip_update_static_peers(cc_agent.id,cc_a2b_server.id,%do_sip,%do_iax) AS foo \n\t\t\t\tFROM cc_a2b_server, cc_agent \n\t\t\t\tWHERE cc_a2b_server.grp = %#srvgrp AND cc_agent.id = %#agentid;", $this->_dirty_vars);
         $dbg_elem->content .= $query . "\n";
         $res = $dbhandle->Execute($query);
         if (!$res) {
             $this->action = 'ask';
             $this->pre_elems[] = new ErrorElem(str_params($this->failureString, array(_("database error")), 1));
             $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
             // 			throw new Exception( $err_str);
             return;
         } elseif ($this->expectRows && $dbhandle->Affected_Rows() < 1) {
             // No result rows: update clause didn't match
             $dbg_elem->content .= ".. EOF, no rows!\n";
             $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
             $dbg_elem->obj = $dbhandle->Affected_Rows();
             $this->pre_elems[] = new ErrorElem(str_params($this->failureString, array(_("no rows")), 1));
             $this->action = 'ask';
             return;
         } else {
             $dbg_elem->content .= "Success: Rows: " . $dbhandle->Affected_Rows() . "\n";
             $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
             if (strlen($this->successString)) {
                 $this->pre_elems[] = new StringElem(str_params($this->successString, array($dbhandle->Affected_Rows()), 1));
             }
             $this->action = 'display';
         }
     }
     //reset
     if ($this->getpost_single('do_sip') == 't') {
         $query = str_aldbparams($dbhandle, "SELECT cc_a2b_server.id AS srvid, cc_a2b_server.host AS srv_host,\n\t\t\t\tpeer.*\n\t\t\t\tFROM cc_a2b_server, static_sip_peers AS peer\n\t\t\t\tWHERE cc_a2b_server.grp = %#srvgrp \n\t\t\t\t  AND cc_a2b_server.id = peer.srvid ORDER BY cc_a2b_server.id, peer.name ;", $this->_dirty_vars);
         $dbg_elem->content .= $query . "\n";
         $res = $dbhandle->Execute($query);
         if (!$res) {
             $this->action = 'ask';
             $this->pre_elems[] = new ErrorElem(str_params($this->failureString, array(_("database error")), 1));
             $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
             // 			throw new Exception( $err_str);
             return;
         } elseif ($this->expectRows && $dbhandle->Affected_Rows() < 1) {
             // No result rows: update clause didn't match
             $dbg_elem->content .= ".. EOF, no rows!\n";
             $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
             $dbg_elem->obj = $dbhandle->Affected_Rows();
             $this->pre_elems[] = new ErrorElem(str_params($this->failureString, array(_("no rows")), 1));
             $this->action = 'ask';
             return;
         } else {
             $dbg_elem->content .= "Success: Rows: " . $dbhandle->Affected_Rows() . "\n";
             $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
             if (strlen($this->successString)) {
                 $this->pre_elems[] = new StringElem(str_params($this->successString, array($dbhandle->Affected_Rows()), 1));
             }
             $this->action = 'display';
             $this->sip_qryres =& $res;
         }
     }
 }
 protected function performSumQuery(&$summ, &$form, &$dbhandle, &$robj)
 {
     $robj->debug("ncols:" . $this->ncols);
     if ($form->FG_DEBUG > 3) {
         $robj->debug("SumMultiView! Building Sum query..");
     }
     if (empty($summ['fns'])) {
         $robj->debug("No sum functions!");
         return;
     }
     $query_fields = array();
     $query_outerfields = array();
     $query_clauses = array();
     $query_grps = array();
     $query_table = $form->model_table;
     $query_outertable = '';
     $need_raw = $robj->NeedRaw();
     foreach ($form->model as $fld) {
         $fld->buildSumQuery($dbhandle, $summ['fns'], $query_fields, $query_outerfields, $query_table, $query_outertable, $query_clauses, $query_grps, $form);
     }
     if (!strlen($query_table)) {
         $robj->debug("No sum table!");
         return;
     }
     $QUERY = 'SELECT ';
     if (count($query_fields) == 0) {
         $robj->debug("No sum query fields!");
         return;
     }
     if (isset($summ['clauses'])) {
         $query_clauses = array_merge($query_clauses, $summ['clauses']);
     }
     $QUERY .= implode(', ', $query_fields);
     $QUERY .= ' FROM ' . $query_table;
     if (count($query_clauses)) {
         $QUERY .= ' WHERE ' . implode(' AND ', $query_clauses);
     }
     if (!empty($query_grps) && (!isset($summ['group']) || $summ['group'] != false)) {
         $QUERY .= ' GROUP BY ' . implode(', ', $query_grps);
     }
     //Try to see if we can order
     if (!empty($form->order)) {
         if (empty($query_grps) || in_array($form->order, $query_grps)) {
             $ordert = $form->order;
         } else {
             // search again for expressions
             foreach ($form->model as $fld) {
                 if ($fld->fieldname == $form->order) {
                     if (in_array($fld->fieldexpr, $query_grps)) {
                         $ordert = $fld->fieldexpr;
                     }
                     break;
                 }
             }
         }
     } elseif (!empty($summ['order'])) {
         $ordert = $summ['order'];
     } else {
         $ordert = null;
     }
     if (!empty($ordert)) {
         $QUERY .= " ORDER BY {$ordert}";
         if (!empty($form->sens)) {
             if (strtolower($form->sens) == 'desc') {
                 $QUERY .= " DESC";
             }
         } elseif (!empty($summ['sens']) && strtolower($summ['sens']) == 'desc') {
             $QUERY .= " DESC";
         }
     }
     if (!empty($summ['limit'])) {
         $QUERY .= ' LIMIT ' . $summ['limit'];
     }
     $needouter = false;
     if (!empty($query_outertable)) {
         $needouter = true;
     } else {
         foreach ($query_outerfields as $qof) {
             if (!is_string($qof)) {
                 $needouter = true;
                 break;
             }
         }
     }
     if ($needouter) {
         $qf2 = array();
         foreach ($query_outerfields as $qof) {
             if (is_string($qof)) {
                 $qf2[] = $qof;
             } elseif (is_array($qof)) {
                 if ($need_raw) {
                     $qf2[] = $qof[1] . ' AS ' . $qof[1] . '_raw';
                 }
                 $qf2[] = $qof[0] . ' AS ' . $qof[1];
             }
         }
         $QUERY = 'SELECT ' . implode(', ', $qf2) . ' FROM ' . '(' . $QUERY . ') AS innerfoo ' . $query_outertable;
     }
     $QUERY .= ';';
     if ($form->FG_DEBUG > 3) {
         $robj->debug("SUM QUERY: {$QUERY}");
     }
     if (!empty($this->queryreplace)) {
         $rrep = false;
         if (isset($this->queryreplace['query'])) {
             $REPQRY = str_alparams($this->queryreplace['query'], array(clauses => implode(' AND ', $query_clauses), fields => implode(', ', $query_fields), grps => $query_grps, table => $query_table));
             if ($form->FG_DEBUG > 3) {
                 $robj->debug("REP QUERY: {$REPQRY}");
             }
             $resRep = $dbhandle->Execute($REPQRY);
             if (!$resRep) {
                 $robj->debug("RepQuery Failed: " . nl2br(htmlspecialchars($dbhandle->ErrorMsg())));
             } else {
                 $rrep = $resRep->fetchRow();
             }
         }
         if (!$rrep) {
             $rrep = $this->queryreplace['default'];
         }
         $QUERY = str_aldbparams($dbhandle, $QUERY, $rrep);
         if ($form->FG_DEBUG > 3) {
             $robj->debug("SUM QUERY after rep: {$QUERY}");
         }
     }
     // Perform the query
     $res = $dbhandle->Execute($QUERY);
     if (!$res) {
         $robj->debug("Query Failed: " . nl2br(htmlspecialchars($dbhandle->ErrorMsg())));
         return;
     }
     return $res;
 }