Exemplo n.º 1
0
    public function RenderSpecial($rmode, &$form, &$robj)
    {
        if ($rmode != 'LaTeX') {
            return;
        }
        $dbhandle =& $form->a2billing->DBHandle();
        $res = $this->performQuery($form, $dbhandle, $rmode);
        if (!$res) {
            return;
        }
        if ($res->EOF) {
            if ($form->list_no_records) {
                echo $list_no_records;
            } else {
                echo str_params(_("No %1 found!"), array($form->model_name_s), 1);
            }
        } else {
            // now, DO render the table!
            ?>
	\begin{tabular}<?php 
            $renrow = array();
            foreach ($form->model as $fld) {
                if ($fld->does_list) {
                    $renrow[] = $fld->fieldtitle;
                }
            }
            echo "{l*" . count($renrow) . "}\n";
            //todo: find actual alignment..
            echo implode(' & ', $renrow);
            //todo: escape
            echo "\\\\ \n";
            while ($row = $res->fetchRow()) {
                if ($form->FG_DEBUG > 4) {
                    echo '%';
                    str_replace("\n", " ", print_r($row, true));
                    echo "\n";
                }
                $renrow = array();
                foreach ($form->model as $fld) {
                    if ($fld->does_list) {
                        $renrow[] = $fld->renderSpecial($row, $form, $rmode, $robj);
                    }
                }
                echo implode(' & ', $renrow);
                //todo: escape
                echo "\\\\ \n";
            }
            ?>
	\end{tabular}
<?php 
        }
        // query table
    }
Exemplo n.º 2
0
 public function DispList(array &$qrow, &$form)
 {
     if ($this->message) {
         $msg = $this->message;
     } else {
         $msg = str_params(_("Details of this %1"), array($form->model_name_s), 1);
     }
     if ($form->getAction() != 'list') {
         return parent::DispList($qrow, $form);
     }
     $pkparams = $form->getPKparams($qrow, true);
     $pkparams[$form->prefix . 'action'] = 'details';
     $url = $_SERVER['PHP_SELF'] . $form->gen_AllGetParams($pkparams);
     echo '<a href="' . $url . '" title="' . $msg . '">';
     parent::DispList($qrow, $form);
     echo '</a>';
 }
Exemplo n.º 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);
     }
     $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;
     }
 }
Exemplo n.º 4
0
 public function RenderSpecial($rmode, &$form, &$robj)
 {
     if ($rmode != 'csv') {
         return;
     }
     $dbhandle =& $form->a2billing->DBHandle();
     $res = $this->performQuery($form, $dbhandle, $rmode);
     if (!$res) {
         return;
     }
     if ($res->EOF) {
         if ($form->list_no_records) {
             echo '# ' . $list_no_records;
         } else {
             echo '# ' . str_params(_("No %1 found!"), array($form->model_name_s), 1);
         }
     } else {
         // now, DO render the table!
         $renrow = array();
         while ($row = $res->fetchRow()) {
             if ($form->FG_DEBUG > 4) {
                 echo '# ';
                 str_replace("\n", " ", print_r($row, true));
                 echo "\n";
             }
             $renrow = array();
             foreach ($form->model as $fld) {
                 if ($fld->does_list) {
                     $renrow[] = $fld->renderSpecial($row, $form, $rmode, $robj);
                 }
             }
             echo implode(', ', $renrow);
             //todo: escape
             echo "\n";
         }
     }
     // query table
 }
Exemplo n.º 5
0
    function Render()
    {
        $action = null;
        $item = _("item");
        if ($this->form) {
            $action = $this->form->getAction();
            $item = $this->form->model_name_s;
        } else {
            $action = getpost_single('action');
        }
        if ($action == 'list') {
            ?>
		<div>
		<a href="<?php 
            echo $_SERVER['PHP_SELF'] . $this->form->gen_AllGetParams(array($this->form->prefix . 'action' => 'ask-add'));
            ?>
"><?php 
            echo str_params(_("Add a new %1"), array($item), 1);
            ?>
</a>
		</div>
		<?php 
        }
    }
Exemplo n.º 6
0
    protected function RenderPages(&$form, &$numrows)
    {
        //automatically choose to use paginating..
        if ($form->ndisp && $numrows >= $form->ndisp || isset($form->cpage) && $form->cpage > 0) {
            $res_count = null;
            if (!empty($this->count_query)) {
                $dbhandle = $form->a2billing->DBHandle();
                if ($form->FG_DEBUG > 3) {
                    echo "<div class=\"debug\">Count Query: " . $this->count_query . "\n</div>\n";
                }
                $tmpres = $dbhandle->Execute($this->count_query);
                if (!$tmpres) {
                    if ($form->FG_DEBUG) {
                        ?>
				<div class="debug"> Cannot count:<?php 
                        echo $dbhandle->ErrorMsg();
                        ?>
</div>
					<?php 
                    }
                } elseif ($tmpres->EOF) {
                    if ($form->FG_DEBUG) {
                        echo "<div class=\"debug\">Count Query: empty result </div>\n";
                    }
                } else {
                    $tmprow = $tmpres->fetchRow();
                    $res_count = $tmprow['coun'];
                }
            }
            ?>
		<table class="paginate">
		<tr><td align="left">
			<form name="<?php 
            echo $form->prefix;
            ?>
otherForm2" action="<?php 
            echo $_SERVER['PHP_SELF'];
            ?>
">
			<?php 
            if (!empty($res_count)) {
                echo str_params(_("%1 Rows,"), array($res_count), 1);
            }
            ?>
			<?php 
            echo _("Display");
            ?>
			<?php 
            echo $form->gen_PostParams(array(cpage => 0));
            ?>
			
			<select name="ndisp" size="1" class="form_input_select">
				<option value="10" selected>10</option>
				<option value="30">30</option>
				<option value="50">50</option>
				<option value="100">100</option>
				<option value="ALL"><?php 
            echo _("All");
            ?>
</option>
			</select>
			<input class="form_input_button"  value=" <?php 
            echo _("GO");
            ?>
 " type="SUBMIT">
			</form>
		</td>
		<td align="right">
		<?php 
            $page_var = $form->prefix . 'cpage';
            //echo "<center><p>\n";
            if ($form->cpage > 0) {
                ?>
			<a href="<?php 
                echo $url . $form->gen_GetParams(array($page_var => 0));
                ?>
" ><?php 
                echo _("First");
                ?>
</a>
			<a href="<?php 
                echo $url . $form->gen_GetParams(array($page_var => $form->cpage - 1));
                ?>
" ><?php 
                echo _("Prev");
                ?>
</a>
			<?php 
            }
            if (!empty($res_count)) {
                $page = $form->cpage;
                $pages = ceil($res_count / $form->ndisp);
                $window = 5;
                if ($page <= $window) {
                    $min_page = 0;
                    $max_page = min(2 * $window, $pages);
                } elseif ($page > $window && $pages > $page + $window) {
                    $min_page = $page - $window;
                    $max_page = $page + $window;
                } else {
                    $min_page = $page - (2 * $window - ($pages - $page));
                    $max_page = $pages - 1;
                }
                // Make sure min_page is always at least 1
                // and max_page is never greater than $pages
                $min_page = max($min_page, 0);
                $max_page = min($max_page, $pages - 1);
                for ($i = $min_page; $i <= $max_page; $i++) {
                    $temp = $url . $form->gen_GetParams(array($page_var => $i));
                    if ($i != $page) {
                        echo "<a class=\"pagenav\" href=\"{$temp}\">" . ($i + 1) . "</a>\n";
                    } else {
                        echo "" . ($i + 1) . "\n";
                    }
                }
            }
            if ($form->ndisp && $numrows >= $form->ndisp) {
                ?>
 <a href="<?php 
                echo $url . $form->gen_GetParams(array($page_var => $form->cpage + 1));
                ?>
" ><?php 
                echo _("Next");
                ?>
</a>
			<?php 
            }
            ?>
		</td></tr>
		<table>
		<?php 
        }
    }
Exemplo n.º 7
0
function reload_userdata($host, $uname, $password, $issip, &$err_msg)
{
    global $FG_DEBUG;
    $as = new AGI_AsteriskManager();
    // && CONNECTING  connect($server=NULL, $username=NULL, $secret=NULL)
    $res = $as->connect($host, $uname, $password);
    if (!$res) {
        $err_msg .= str_params(_("<p><font color=red>Cannot connect to asterisk manager @%1<br>Please check manager configuration...</font></p>"), array($host), 1);
        return false;
    }
    if ($issip) {
        $res = $as->Command('sip reload');
    } else {
        $res = $as->Command('iax2 reload');
    }
    if ($res) {
        $err_msg .= str_params(_("<p><font color=green>The %2 file at %1 has been reload</font></p>"), array($host, $issip ? 'sip' : 'iax'));
    }
    return $res;
}
Exemplo n.º 8
0
 function PerformQuery(&$form)
 {
     $dbhandle =& $form->a2billing->DBHandle();
     if ($form->FG_DEBUG > 3) {
         echo "<div class=\"debug\">Details! Building query..</div>";
     }
     $query_fields = array();
     $query_clauses = array();
     $query_table = $form->model_table;
     foreach ($form->model as $fld) {
         $tmp = $fld->detailQueryField($dbhandle);
         if (is_string($tmp)) {
             $query_fields[] = $tmp;
         } elseif (is_array($tmp)) {
             $query_fields = array_merge($query_fields, $tmp);
         }
         $tmp = $fld->detailQueryClause($dbhandle, $form);
         if (is_string($tmp)) {
             $query_clauses[] = $tmp;
         }
         $fld->detailQueryTable($query_table, $form);
     }
     if (!strlen($query_table)) {
         if ($form->FG_DEBUG > 0) {
             echo "<div class=\"debug\">No table!</div>\n";
         }
         return;
     }
     $QUERY = 'SELECT ';
     if (count($query_fields) == 0) {
         if ($form->FG_DEBUG > 0) {
             echo "<div class=\"debug\">No query fields!</div>\n";
         }
         return;
     }
     $QUERY .= implode(', ', $query_fields);
     $QUERY .= ' FROM ' . $query_table;
     if (count($query_clauses)) {
         $QUERY .= ' WHERE ' . implode(' AND ', $query_clauses);
     }
     $QUERY .= ' LIMIT 1;';
     // we can only edit one record at a time!
     if ($form->FG_DEBUG > 3) {
         echo "<div class=\"debug\">QUERY: {$QUERY}</div>\n";
     }
     // Perform the query
     $res = $dbhandle->Execute($QUERY);
     if (!$res) {
         if ($form->FG_DEBUG > 0) {
             echo "<div class=\"debug\">Query Failed: " . nl2br(htmlspecialchars($dbhandle->ErrorMsg())) . "</div>";
         }
         return;
     }
     if ($res->EOF) {
         if ($form->edit_no_records) {
             echo $form->edit_no_records;
         } else {
             echo str_params(_("No %1 found!"), array($form->model_name_s), 1);
         }
     }
     return $res;
 }
Exemplo n.º 9
0
 public function DispList(array &$qrow, &$form)
 {
     if ($this->message) {
         $msg = $this->message;
     } else {
         $msg = str_params(_("Details of %1"), array($form->model_name_s), 1);
     }
     $pkparams = $form->getPKparams($qrow, true);
     $pkparams[$form->prefix . 'action'] = 'details';
     $url = $_SERVER['PHP_SELF'] . $form->gen_AllGetParams($pkparams);
     echo '&nbsp;<a href="' . $url . '" title="' . $msg . '">';
     echo '<img src="' . $this->img . '" border="0" alt="' . $msg . '">';
     echo '</a>';
 }
Exemplo n.º 10
0
    /** Produce the separator with Tabs for Del View
     */
    public function DispTabDel($val, &$form, $id_fragment)
    {
        if ($id_fragment > 1) {
            ?>
			<tr class="confirm"><td colspan=2 align="right">
			<button type=submit>
			<?php 
            echo str_params(_("Delete this %1"), array($form->model_name_s), 1);
            ?>
			<img src="./Images/icon_arrow_orange.png" ></button>
			<td>
			</tr>
			</tbody></table></div>
			<?php 
        }
        echo '<div id="fragment-' . $id_fragment . '">';
        if ($id_fragment > 1) {
            ?>
			<table class="detailForm" cellspacing="2">
				<thead><tr><td class="field">&nbsp;</td><td class="value">&nbsp;</td></tr></thead>
				<tbody>
			<?php 
        }
    }
Exemplo n.º 11
0
 public function PerformAction(&$form)
 {
     $dbg_elem = new DbgElem();
     $dbhandle = $form->a2billing->DBHandle();
     if (!isset($this->importEngine)) {
         $this->importEngine = new $this->impEngClass();
         $this->importEngine->Init(array_merge($this->impEngArgs, array('db' => $dbhandle)));
     }
     if ($form->FG_DEBUG > 0) {
         array_unshift($form->pre_elems, $dbg_elem);
     }
     if ($form->FG_DEBUG > 2) {
         $dbg_elem->content .= print_r($_POST, true) . "\n";
     }
     $fil = $_FILES[$form->prefix . 'the_file'];
     if (!isset($fil)) {
         $form->pre_elems[] = new ErrorElem(_("File has not been posted at all!"));
         $form->setAction('ask-import');
         return;
     }
     switch ($fil['error']) {
         case UPLOAD_ERR_OK:
             $dbg_elem->content .= "File uploaded OK.\n";
             break;
         case UPLOAD_ERR_INI_SIZE:
             $form->pre_elems[] = new ErrorElem(str_params(_("File size exceeds %1 limit of the system!"), array(123), 1));
             $dbg_elem->content .= "Error!\n";
             $form->setAction('ask-import');
             return;
         case UPLOAD_ERR_FORM_SIZE:
             $form->pre_elems[] = new ErrorElem(str_params(_("File size exceeds %1 limit for this action!"), array(123), 1));
             $dbg_elem->content .= "Error!\n";
             $form->setAction('ask-import');
             return;
         case UPLOAD_ERR_PARTIAL:
             $form->pre_elems[] = new ErrorElem(_("The uploaded file was only partially uploaded."));
             $dbg_elem->content .= "Error!\n";
             $form->setAction('ask-import');
             return;
         case UPLOAD_ERR_NO_FILE:
             $form->pre_elems[] = new ErrorElem(_("No file was uploaded."));
             $dbg_elem->content .= "Error!\n";
             $form->setAction('ask-import');
             return;
         case UPLOAD_ERR_NO_TMP_DIR:
             $form->pre_elems[] = new ErrorElem(_("Internal error, could not upload."));
             $dbg_elem->content .= "Missing a temporary folder. \n";
             $form->setAction('ask-import');
             return;
         case UPLOAD_ERR_CANT_WRITE:
             $form->pre_elems[] = new ErrorElem(_("Internal error, could not upload."));
             $dbg_elem->content .= "Failed to write file to disk.\n";
             $form->setAction('ask-import');
             return;
         default:
             $form->pre_elems[] = new ErrorElem(_("Internal error, could not upload."));
             $dbg_elem->content .= "Unknown error:" . $fil['error'] . "\n";
             $form->setAction('ask-import');
             return;
     }
     $allowed_mimetypes = $this->importEngine->getMimeTypes();
     if (!in_array($fil['type'], $allowed_mimetypes)) {
         $form->pre_elems[] = new ErrorElem(str_params(_("Cannot accept file of type %1. Allowed types are: %2."), array($fil['type'], implode(', ', $allowed_mimetypes)), 1));
         $dbg_elem->content .= "Cannot accept file type \n";
         $form->setAction('ask-import');
         return;
     }
     //Now, check the given fields
     $tmpdir = DynConf::GetCfg('global', 'upload_tmpdir', '/tmp');
     $tmpname = str_replace('/', '-', basename($fil['name']));
     $tmpname = tempnam($tmpdir, $tmpname);
     if ($tmpname === false) {
         $form->pre_elems[] = new ErrorElem(_("Internal error, could not upload."));
         $dbg_elem->content .= "Cannot make temp file in {$tmpdir} \n";
         $form->setAction('ask-import');
         return;
     }
     if (move_uploaded_file($fil['tmp_name'], $tmpname)) {
         $dbg_elem->content .= "moved  \"" . $fil['tmp_name'] . "\" to \"" . $tmpname . "\"\n";
         $this->movedFile = $tmpname;
     } else {
         $form->pre_elems[] = new ErrorElem(_("Internal error, could not upload."));
         $dbg_elem->content .= "Cannot move uploaded file to temporary. \n";
         $form->setAction('ask-import');
         return;
     }
 }
Exemplo n.º 12
0
 public function PerformAction(&$form)
 {
     $dbg_elem = new DbgElem();
     $dbhandle = $form->a2billing->DBHandle();
     if ($form->FG_DEBUG > 0) {
         array_unshift($form->pre_elems, $dbg_elem);
     }
     // just build the value list..
     $ins_data = array();
     try {
         foreach ($form->model as $fld) {
             $fld->buildInsert($ins_data, $form);
         }
     } catch (Exception $ex) {
         $form->setAction('ask-add2');
         $form->pre_elems[] = new ErrorElem($ex->getMessage());
         $dbg_elem->content .= $ex->message . ' (' . $ex->getCode() . ")\n";
         // 			throw new Exception( $err_str);
     }
     $ins_keys = array();
     $ins_values = array();
     $ins_qm = array();
     foreach ($ins_data as $ins) {
         $ins_keys[] = $ins[0];
         if (count($ins) > 2) {
             $ins_qm[] = $ins[2];
         } else {
             $ins_qm[] = '?';
         }
         $ins_values[] = $ins[1];
     }
     if (substr($form->model_table, 0, 5) == 'ONLY ') {
         $mtable = substr($form->model_table, 5);
     } else {
         $mtable = $form->model_table;
     }
     $dbg_elem->content .= "Query: INSERT INTO " . $mtable . "(";
     $dbg_elem->content .= implode(', ', $ins_keys);
     $dbg_elem->content .= ") VALUES(" . var_export($ins_values, true) . ");\n";
     $query = "INSERT INTO " . $mtable . "(" . implode(', ', $ins_keys) . ") VALUES(" . implode(',', $ins_qm) . ");";
     /* Note: up till now, no data has been quoted/sanitized. Thus, we
        feed it direcltly to the second part of the query. Pgsql, in particular,
        can handle a binary transfer of that data to the db, in a well protected
        manner */
     if (session_readonly()) {
         $dbg_elem->content .= "Read-only: query not performed.\n";
         $form->pre_elems[] = new StringElem(_("Read only. No data has been altered."));
         $form->setAction('list');
         return;
     }
     $res = $dbhandle->Execute($query, $ins_values);
     if (!$res) {
         $form->setAction('ask-add2');
         $form->pre_elems[] = new ErrorElem(str_params(_("Cannot create new %1, database error."), array($form->model_name_s), 1));
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         // 			throw new Exception( $err_str);
     } else {
         $dbg_elem->content .= ".. success: " . gettype($res) . "\n";
         $form->pre_elems[] = new StringElem(_("New data has successfully been inserted into the database."));
         $form->setAction('list');
     }
 }
Exemplo n.º 13
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;
         }
     }
 }
Exemplo n.º 14
0
 $sql_str = "ABORT;";
 switch ($export_style) {
     case 'peer-full-csv':
         array_push($export_fields, 'buyrate', 'buyrateinitblock', 'buyrateincrement', 'rateinitial', 'initblock', 'billingblock', 'connectcharge', 'disconnectcharge', 'stepchargea', 'chargea', 'timechargea', 'billingblocka', 'stepchargeb', 'chargeb', 'timechargeb', 'billingblockb', 'stepchargec', 'chargec', 'timechargec', 'billingblockc');
         $sql_str = str_dbparams($DBHandle, 'SELECT ' . implode(', ', $export_fields) . ' FROM cc_ratecard WHERE idtariffplan = %1;', array($id_tp));
         $log_str = "Ratecard #%0 exported in csv format, all fields in peer format";
         $myfileName = "Ratecard_" . $tp_id;
         $prolog = "# Export of tp #{$id_tp}\n";
         $prolog .= "#fields: " . implode(';', $export_fields) . "\n";
         break;
     default:
         echo "Wrong export style:" . $export_style . "\n<br>\n";
         die;
 }
 $myfileName .= date("Y-m-d");
 $log->insertLog($_SESSION["admin_id"], 2, "FILE EXPORTED", str_params($log_str, array($id_tp, $export_style)), '', $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'], '');
 $dumpfile->sep = ';';
 $dumpfile->prolog = $prolog;
 $dumpfile->dump($sql_str, $myfileName, "csv", DBNAME, USER, PASS, HOST, DB_TYPE);
 DBDisconnect($DBHandle);
 /*  if(strcmp($var_export_type,"type_csv")==0)
     {
 		$myfileName = "Dump_". date("Y-m-d");
 		$log -> insertLog($_SESSION["admin_id"], 2, "FILE EXPORTED", "A File in CSV Format is exported by User, File Name= ".$myfileName.".csv", '', $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'],'');
         $dumpfile->dump($_SESSION[$var_export], $myfileName, "csv", DBNAME, USER, PASS, HOST, DB_TYPE );
     }
     elseif(strcmp($var_export_type,"type_xml")==0)
     {
         $myfileName = "Dump_". date("Y-m-d");
 		$log -> insertLog($_SESSION["admin_id"], 2, "FILE EXPORTED", "A File in XML Format is exported by User, File Name= ".$myfileName.".xml", '', $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI'],'');
 		$dumpfile->dump($_SESSION[$var_export], $myfileName, "xml", DBNAME, USER, PASS, HOST, DB_TYPE );
Exemplo n.º 15
0
 /** Format and execute the Update query */
 public function PerformAction(&$form)
 {
     $dbg_elem = new DbgElem();
     $dbhandle = $form->a2billing->DBHandle();
     if ($form->FG_DEBUG > 0) {
         array_unshift($form->pre_elems, $dbg_elem);
     }
     // just build the value list..
     $upd_data = array();
     $upd_clauses = array();
     try {
         foreach ($form->model as $fld) {
             $fld->buildUpdate($upd_data, $form);
             $qc = $fld->editQueryClause($dbhandle, $form);
             if ($qc) {
                 if (is_string($qc)) {
                     $upd_clauses[] = $qc;
                 } elseif (is_array($qc)) {
                     $upd_clauses = array_merge($upd_clauses, $qc);
                 } else {
                     throw new Exception("Why clause " . gettype($qc) . " ?");
                 }
             }
         }
     } catch (Exception $ex) {
         $form->action = 'ask-edit2';
         $form->pre_elems[] = new ErrorElem($ex->getMessage());
         $dbg_elem->content .= $ex->getMessage() . ' (' . $ex->getCode() . ")\n";
         // 			throw new Exception( $err_str);
     }
     $upd_values = array();
     $query = "UPDATE " . $form->model_table . " SET ";
     $query_u = array();
     foreach ($upd_data as $upd) {
         if (is_array($upd)) {
             $query_u[] = $upd[0] . " = ? ";
             $upd_values[] = $upd[1];
         } elseif (is_string($upd)) {
             $query_u[] = $upd;
         }
     }
     $query .= implode(", ", $query_u);
     $query_dbg = $query;
     // format a string that contains the values, too
     $query_dbg .= "( " . var_export($upd_values, true) . ") ";
     // Protect against a nasty update!
     if (count($upd_clauses) < 1) {
         $form->pre_elems[] = new ErrorElem("Cannot update, internal error");
         $dbg_elem->content .= "Update: no query clauses!\n";
     }
     $query .= ' WHERE ' . implode(' AND ', $upd_clauses) . ';';
     $query_dbg .= ' WHERE ' . implode(' AND ', $upd_clauses) . ';';
     $dbg_elem->content .= $query_dbg . "\n";
     /* Note: up till now, no data has been quoted/sanitized. Thus, we
        feed it direcltly to the second part of the query. Pgsql, in particular,
        can handle a binary transfer of that data to the db, in a well protected
        manner */
     if (session_readonly()) {
         $dbg_elem->content .= "Read-only: query not performed.\n";
         $form->pre_elems[] = new StringElem(_("Read only. No data has been altered."));
         $form->setAction('list');
         return;
     }
     $res = $dbhandle->Execute($query, $upd_values);
     if (!$res) {
         $form->setAction('ask-edit2');
         $form->pre_elems[] = new ErrorElem(str_params(_("Cannot update %1, database error."), array($form->model_name_s), 1));
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         // 			throw new Exception( $err_str);
     } elseif ($dbhandle->Affected_Rows() < 1) {
         // No result rows: update clause didn't match
         $dbg_elem->content .= ".. EOF, no rows!";
         $dbg_elem->obj = $dbhandle->Affected_Rows();
         $form->pre_elems[] = new ErrorElem(str_params(_("Cannot update %1, record not found."), array($form->model_name_s), 1));
         $form->setAction('ask-edit2');
     } else {
         $dbg_elem->content .= "Success: UPDATE " . $dbhandle->Affected_Rows() . "\n";
         $form->pre_elems[] = new StringElem(_("Data has successfully been updated in the database."));
         $form->setAction('list');
     }
 }
 public function RenderContent()
 {
     $t = $this->getpost_single('type');
     $entry = null;
     foreach ($this->prentries as $e) {
         if ($e[0] == $t) {
             $entry = $e;
             break;
         }
     }
     if ($entry == null) {
         echo "<div class=\"error\">" . _("Invalid type!") . "</div>\n";
         return false;
     }
     if ($this->FG_DEBUG > 2) {
         echo "<div class=\"debug\">";
         echo "ProvisionActionForm::RenderContent(): ";
         print_r($entry);
         echo "</div>\n";
     }
     $proengine = null;
     $dbg_elem = new DbgElem();
     if ($this->FG_DEBUG > 1) {
         $dbg_elem->content .= "Args: " . print_r($this->prov_args, true) . "\n";
     }
     // Now, process the entry and load the Provision engine
     try {
         switch ($entry[2]) {
             case 'ast-ini':
                 require_once DIR_COMMON . "Provi/AsteriskIni.inc.php";
                 $proengine = new AsteriskIniProvi();
                 $proengine->dbg_elem =& $dbg_elem;
                 $proengine->Init(array_merge($this->prov_args, array(categ => $entry[3])));
                 break;
             default:
                 if ($this->FG_DEBUG) {
                     echo "Invalid categ " . $entry[2] . " specified in source.<br>\n";
                 }
                 return;
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         echo "\n";
         if ($this->FG_DEBUG) {
             $dbg_elem->Render();
         }
         return;
     }
     $fp = fopen('php://temp', 'r+');
     if (!$fp) {
         if ($this->FG_DEBUG) {
             echo "Cannot open temp stream.<br>\n";
         }
         return;
     }
     $proengine->genContent($fp);
     if ($this->FG_DEBUG) {
         $dbg_elem->Render();
     }
     // the temporary stream at $fp holds the data. Rewind it and print
     // properly
     rewind($fp);
     echo "<div>" . str_params(_("Here is your example %1:"), array($entry[1]), 1) . "</div>\n";
     echo '<div class=\\"provi\\">';
     echo nl2br(htmlspecialchars(stream_get_contents($fp)));
     echo "</div>\n";
     fclose($fp);
 }
Exemplo n.º 17
0
/** One function that sets up page elems for an agent-session invoice */
function AgentSessionInvoice($sess_row, $rights, $booth_page)
{
    global $PAGE_ELEMS;
    global $FG_DEBUG;
    $dbhandle = A2Billing::DBHandle();
    $HD_Form = new FormHandler('cc_session_invoice', _("Transactions"), _("Transaction"));
    $HD_Form->checkRights($rights);
    $HD_Form->init(null, false);
    $HD_Form->views['list'] = new ListSumView();
    $HD_Form->views['pay'] = $HD_Form->views['true'] = $HD_Form->views['false'] = new IdleView();
    if ($FG_DEBUG) {
        $HD_Form->views['dump-form'] = new DbgDumpView();
    }
    $PAGE_ELEMS[] =& $HD_Form;
    $HD_Form->model[] = new ClauseField('sid', $sess_row['sid']);
    $HD_Form->model[] = new DateTimeField(_("Date"), 'starttime');
    $HD_Form->model[] = new TextField(_("Description"), 'descr');
    end($HD_Form->model)->fieldacr = _("Descr");
    $HD_Form->model[] = new TextField("", 'f2');
    $HD_Form->model[] = new TextField(_("Called Number"), 'cnum');
    end($HD_Form->model)->fieldacr = _("C. Num");
    //end($HD_Form->model)->fieldname ='agent';
    $HD_Form->model[] = new SecondsField(_("Duration"), "duration");
    end($HD_Form->model)->fieldacr = _("Dur");
    $HD_Form->model[] = new MoneyField(_("Credit"), "pos_charge");
    $HD_Form->model[] = new MoneyField(_("Charge"), "neg_charge");
    $HD_Form->views['list']->sum_fns = array('duration' => 'SUM', 'pos_charge' => 'SUM', 'neg_charge' => 'SUM');
    // Per date calls..
    $Sum_Form = new FormHandler('cc_session_calls', _("Per-date calls"));
    $Sum_Form->checkRights($rights);
    $Sum_Form->init(null, false);
    $Sum_Form->views['list'] = new SumMultiView();
    $Sum_Form->views['pay'] = $Sum_Form->views['true'] = $Sum_Form->views['false'] = new IdleView();
    if ($FG_DEBUG) {
        $Sum_Form->views['dump-form'] = new DbgDumpView();
    }
    $PAGE_ELEMS[] =& $Sum_Form;
    $Sum_Form->model[] = new ClauseField('sid', $sess_row['sid']);
    $Sum_Form->model[] = new DateField(_("Date"), 'starttime');
    end($Sum_Form->model)->fieldexpr = 'date_trunc(\'day\', starttime)';
    $Sum_Form->model[] = new IntField(_("Calls"), 'cnum');
    $Sum_Form->model[] = new SecondsField(_("Duration"), "duration");
    //$Sum_Form->model[] = new FloatField(_("Credit"), "pos_charge");
    $Sum_Form->model[] = new MoneyField(_("Charge"), "neg_charge");
    if ($sess_row['has_days'] == 't') {
        $Sum_Form->views['list']->sums[] = array('title' => _("Per day calls"), 'fns' => array('starttime' => true, 'cnum' => 'COUNT', 'duration' => 'SUM', 'neg_charge' => 'SUM'));
    }
    $Sum_Form->views['list']->sums[] = array('title' => _("Total"), 'fns' => array('cnum' => 'COUNT', 'duration' => 'SUM', 'neg_charge' => 'SUM'));
    if ($sess_row['is_open'] != 't') {
        $PAGE_ELEMS[] = new StringElem(_("Session is closed"));
    } elseif ($sess_row['is_inuse'] == 't') {
        $PAGE_ELEMS[] = new StringElem(_("Card is in use, cannot close session now."));
    } else {
        $pay_form = new SqlActionElem();
        $pay_form->action_do = 'pay';
        $pay_form->action_ask = 'list';
        $pay_form->init();
        $PAGE_ELEMS[] =& $pay_form;
        if ($sess_row['credit'] > 0) {
            $pay_form->ButtonStr = str_params(_("Pay back %1"), array($sess_row['credit_fmt']), 1);
            $pay_form->elem_success = new StringElem(_("Sesion paid back!"));
        } else {
            $pay_form->ButtonStr = str_params(_("Pay %1"), array($sess_row['credit_fmt']), 1);
            $pay_form->elem_success = new StringElem(_("Sesion paid!"));
        }
        $pay_form->follow_params['sum'] = $sess_row['credit'];
        $pay_form->follow_params['sid'] = $sess_row['sid'];
        $pay_form->QueryString = str_dbparams($dbhandle, 'SELECT pay_session(%1, %2, true) AS money;', array($sess_row['sid'], $_GET['sum']));
        $pay_form->elem_fail = new StringElem(_("Session could not be paid!"));
        $pay_form->elem_success->content .= "\n<br><a href=\"{$booth_page}\">" . _("Back to booths") . "</a>";
    }
}
Exemplo n.º 18
0
 public function buildSumQuery(&$dbhandle, &$sum_fns, &$fields, &$fields_out, &$table, &$table_out, &$clauses, &$grps, &$form)
 {
     if (!$this->does_list) {
         return;
     }
     // fields
     if ($this->fieldexpr) {
         $fld = $this->fieldexpr;
     } else {
         $fld = $this->fieldname;
     }
     if (isset($sum_fns[$this->fieldname]) && !is_null($sum_fns[$this->fieldname])) {
         if ($sum_fns[$this->fieldname] === true) {
             $grps[] = $this->fieldname;
             $fields[] = "{$fld} AS " . $this->fieldname;
         } elseif (is_string($sum_fns[$this->fieldname])) {
             $fields[] = $sum_fns[$this->fieldname] . "({$fld}) AS " . $this->fieldname;
         } elseif (is_array($sum_fns[$this->fieldname])) {
             $fields[] = str_dbparams($dbhandle, '%1 AS ' . $this->fieldname, $sum_fns[$this->fieldname]);
         }
         $rclause = '';
         if (!empty($this->refclause)) {
             $rclause = ' WHERE ' . $this->refclause;
         }
         if ($this->refexpr) {
             $refname = $this->refexpr;
         } else {
             $refname = $this->refname;
         }
         $table_out .= ' LEFT OUTER JOIN ' . str_params("( SELECT %1 AS %0_%1, %4 AS %0_%2 FROM %3 {$rclause}) AS %0_table " . "ON %0_%1 = %0", array($this->fieldname, $this->refid, $this->refname, $this->reftable, $refname));
         $fields_out[] = $this->fieldname;
         $fields_out[] = $this->fieldname . '_' . $this->refid;
         $fields_out[] = $this->fieldname . '_' . $this->refname;
         $tmp = $this->listQueryClause($dbhandle, $form);
         if (is_string($tmp)) {
             $clauses[] = $tmp;
         }
     }
 }
Exemplo n.º 19
0
	<tr>
	<td width="35%">&nbsp; </td>
	<td width="65%">&nbsp; </td>
	</tr>
	<tr>
	<td><?php 
echo gettext("Amount");
?>
&nbsp;: </td>
	<td><?php 
echo htmlspecialchars($info_invoice['amount']);
?>
</td>
	<tr>
	<td><?php 
echo str_params(gettext("VAT (%1)%%"), array($info_invoice['vat']), 1);
?>
&nbsp;: </td>
	<td><?php 
echo htmlspecialchars($info_invoice['tax']);
?>
</td>
	</tr>
	<tr>
	<td><?php 
echo gettext("Total");
?>
&nbsp;: </td>
	<td><?php 
display_dateformat($info_invoice['total']);
?>
Exemplo n.º 20
0
 if (!$dbh) {
     echo "Cannot connect to database, exiting..";
     break;
 }
 $as = new AGI_AsteriskManager();
 if ($verbose < 2) {
     $as->nolog = true;
 } else {
     if ($verbose > 3) {
         $as->debug = true;
     }
 }
 // && CONNECTING  connect($server=NULL, $username=NULL, $secret=NULL)
 $res = $as->connect($host, $uname, $password);
 if (!$res) {
     echo str_params(_("Cannot connect to asterisk manager @%1. Please check manager configuration...\n"), array($host), 1);
     sleep(60);
     continue;
 }
 if ($verbose > 2) {
     echo "Connected to asterisk.\n";
 }
 //$res = $as->Ping();
 $as->Events('agent,call');
 $as->add_event_handler('Join', handle_handler);
 $as->add_event_handler('Leave', idle_handler);
 $as->add_event_handler('QueueCallerAbandon', handle_handler);
 $as->add_event_handler('AgentCalled', handle_handler);
 $as->add_event_handler('AgentDump', handle_handler);
 $as->add_event_handler('AgentConnect', handle_handler);
 $as->add_event_handler('AgentComplete', handle_handler);
Exemplo n.º 21
0
function manager_multiconnect(array $srvnames)
{
    global $manager_connections;
    global $dbh;
    global $verbose;
    if (empty($srvnames)) {
        return false;
    }
    $srv_hostnames = array();
    $srv_grps = array();
    foreach ($srvnames as $serverhost) {
        echo "Want to connect to {$serverhost}.. \n";
        if ($serverhost[0] == '@') {
            $srv_grps[] = $dbh->Quote(substr($serverhost, 1));
        } else {
            $srv_hostnames[] = $dbh->Quote($serverhost);
        }
    }
    if (empty($srv_hostnames)) {
        $qry_hostclause = 'FALSE';
    } else {
        $qry_hostclause = 'host IN(' . implode($srv_hostnames, ', ') . ')';
    }
    if (empty($srv_grps)) {
        $qry_grpclause = 'FALSE';
    } else {
        $qry_grpclause = 'grp IN( SELECT id FROM cc_server_group ' . 'WHERE name IN (' . implode($srv_grps, ', ') . ') )';
    }
    $qry = 'SELECT DISTINCT id, host, ip, manager_username, manager_secret FROM cc_a2b_server ' . ' WHERE ' . $qry_hostclause . ' OR ' . $qry_grpclause . ';';
    if ($verbose > 2) {
        echo "Query: {$qry} \n";
    }
    $res = $dbh->Execute($qry);
    if (!$res) {
        echo $dbh->ErrorMsg() . "\n";
        return false;
    } elseif ($res->EOF) {
        if ($verbose > 1) {
            echo "No a2b servers found.\n";
        }
        return false;
    } else {
        while ($row = $res->fetchRow()) {
            if (!empty($row['ip'])) {
                $host = $row['ip'];
            } else {
                $host = $row['host'];
            }
            $uname = $row['manager_username'];
            $as = new AGI_AsteriskManager();
            $as->nolog = true;
            if ($verbose > 2) {
                echo "Manager connect to {$uname}@{$host}..\n";
            }
            if (!$as->connect($host, $uname, $row['manager_secret'])) {
                $err_msg .= str_params(_("Cannot connect to asterisk manager @%1<br>Please check manager configuration..."), array($host), 1);
                if ($verbose) {
                    echo $err_str;
                }
                continue;
            }
            $manager_connections[$row['id']] = $as;
        }
    }
    return count($manager_connections) > 0;
}
Exemplo n.º 22
0
    public function Render(&$form)
    {
        $dbhandle = $form->a2billing->DBHandle();
        $fldIndex = array();
        ?>
<div class='impA-progress' name="<?php 
        echo $form->prefix;
        ?>
iprogress">
			<?php 
        echo _("Importing uploaded data...");
        ?>
			<span name="<?php 
        echo $form->prefix;
        ?>
icount"> </span>
		<div>
		
		<?php 
        // Construct, again, the list of fields
        foreach ($form->model as $key => $fld) {
            if ($fld->fieldname) {
                $fldIndex[$fld->fieldname] = $key;
            }
        }
        $fields2 = array();
        $returning = array();
        $fields = explode(',', $_SESSION[$form->prefix . 'importFields']);
        foreach ($fields as $fld) {
            $retk = null;
            $ext = false;
            //does it aggregate over CSV rows?
            $aggr = in_array($fld, $this->askImport->multiple);
            // does it belong to the primary INSERT or to
            // some subsequent?
            if ($form->model[$fldIndex[$fld]] instanceof RevRef) {
                $ext = true;
                $retk = $form->model[$fldIndex[$fld]]->localkey;
            }
            $fields2[] = array($fld, $fldIndex[$fld], $aggr, $ext, $retk);
        }
        unset($fields);
        if ($form->FG_DEBUG > 4) {
            echo nl2br(htmlspecialchars(print_r($fields2, true)));
            echo "<br>\n";
        }
        // Build primary INSERT
        $ins_keys = array();
        //$ins_values = array();
        $ins_qm = array();
        $ins_returning = array();
        // Find
        foreach ($this->askImport->common as $fld) {
            $ins_keys[] = $fld;
            $ins_qm[] = str_dbparams($dbhandle, "%!1", array($form->model[$fldIndex[$fld]]->buildValue($form->getpost_dirty($fld), $form)));
        }
        foreach ($fields2 as $fld) {
            if (!$fld[3]) {
                $ins_keys[] = $fld[0];
                $ins_qm[] = '?';
            } else {
                $ins_returning[] = $fld[4];
            }
        }
        $insert_pri = "INSERT INTO " . $form->model_table . "(" . implode(', ', $ins_keys) . ") VALUES(" . implode(',', $ins_qm) . ")";
        if (count($ins_returning)) {
            $insert_pri .= " RETURNING " . implode(', ', $ins_returning);
        }
        $insert_pri .= ";";
        if ($form->FG_DEBUG > 1) {
            echo "Insert query: " . htmlspecialchars($insert_pri) . "<br>\n";
        }
        $fp = fopen($this->movedFile, "r");
        if (!$fp) {
            ?>
<div class="error">
				<?php 
            echo _("Error: Cannot open uploaded file");
            ?>
			</div>
			<?php 
            return;
        }
        $nrows = 0;
        $nlines = 0;
        $delimiter = $this->askImport->delimiter;
        $multi_sep = $this->askImport->multi_sep;
        $last_a = null;
        $reted = null;
        // 		$last_b = null;
        //Everything must be in one transaction, to avoid partially imported
        //data
        $dbhandle->StartTrans();
        // The actual import loop!
        while (($larr = fgetcsv($fp, 4096, $delimiter)) !== false) {
            if ($larr === null) {
                continue;
            }
            if (count($larr) < count($fields2)) {
                if ($form->FG_DEBUG) {
                    echo "Less fields came!<br>\n";
                }
                if ($form->FG_DEBUG > 2) {
                    echo nl2br(print_r($larr, true) . "\n");
                }
                $dbhandle->FailTrans();
                break;
            }
            $nlines++;
            $arr_a = array();
            $arr_b = array();
            $arr_ext = array();
            //split the data into 2 arrays.
            foreach ($fields2 as $fld) {
                $val = $form->model[$fld[1]]->buildValue(current($larr), $form);
                if (!$fld[2]) {
                    $arr_a[] = $val;
                } else {
                    if (!$fld[3]) {
                        $arr_b[] = $val;
                    } else {
                        $arr_c[$fld[0]] = $val;
                    }
                }
                next($larr);
            }
            //If non-multiple data matches, we reuse the line
            if ($this->askImport->distinct && $arr_a == $last_a) {
            } else {
                if ($form->FG_DEBUG > 2 && $nrows < 100) {
                    echo "Data:" . htmlspecialchars(implode(', ', $arr_a)) . "<br>\n";
                }
                $res = $dbhandle->Execute($insert_pri, $arr_a);
                if (!$res) {
                    ?>
				<div class="error">
					<?php 
                    echo _("Database error, cannot import!");
                    ?>
				</div>
				<?php 
                    if ($form->FG_DEBUG) {
                        echo $dbhandle->ErrorMsg();
                        echo "<br>\n";
                    }
                    $dbhandle->FailTrans();
                    return;
                } elseif (count($ins_returning) && $res->EOF) {
                    ?>
				<div class="error">
					<?php 
                    echo _("Database error, rows not imported!");
                    ?>
				</div>
				<?php 
                    if ($form->FG_DEBUG) {
                        echo "No result from insert operation!";
                        echo "<br>\n";
                    }
                    $dbhandle->FailTrans();
                    return;
                } else {
                    $reted = $res->fetchRow();
                }
                if ($form->FG_DEBUG && !$res->EOF) {
                    echo "Second result after INSERT? weird..<br>\n";
                }
                if ($form->FG_DEBUG > 2 && $nlines < 10 && count($ins_returning)) {
                    echo "Returned: " . print_r($reted, true) . "<br>\n";
                }
                $last_a = $arr_a;
                $nrows++;
            }
            if (count($arr_c)) {
                foreach ($fields2 as $fld) {
                    if (!$fld[3]) {
                        continue;
                    }
                    $mfld =& $form->model[$fld[1]];
                    $cqry = "INSERT INTO {$mfld->reftable} ({$mfld->refid}, {$mfld->refname}) VALUES ";
                    $data = explode($multi_sep, $arr_c[$fld[0]]);
                    if (!count($data)) {
                        continue;
                    }
                    $cqry_val = array();
                    foreach ($data as $dat) {
                        $cqry_val[] = str_dbparams($dbhandle, "(%1, %2)", array($reted[$mfld->localkey], $dat));
                    }
                    $cqry .= implode(",\n", $cqry_val) . ";";
                    if ($form->FG_DEBUG > 2 && $nlines < 100) {
                        echo "Extra: " . htmlspecialchars($cqry) . "<br>\n";
                    }
                    $res = $dbhandle->Execute($cqry);
                    if (!$res) {
                        ?>
				<div class="error">
					<?php 
                        echo _("Database error, secondary rows not imported!");
                        ?>
				</div>
				<?php 
                        if ($form->FG_DEBUG) {
                            if ($form->FG_DEBUG > 2) {
                                echo "Query: " . htmlspecialchars($cqry) . "<br>\n";
                            }
                            echo $dbhandle->ErrorMsg();
                            echo "<br>\n";
                        }
                        $dbhandle->FailTrans();
                        return;
                    }
                }
            }
            if ($nlines % 1000 == 0) {
                // reset the timer and give us another 20sec
                set_time_limit(20);
                if ($form->FG_DEBUG > 1) {
                    echo "Rows found: {$nrows}<br>\n";
                }
                ?>
	<script language="JavaScript" type="text/javascript">
	document.getElementsByName("<?php 
                echo $form->prefix;
                ?>
icount")[0].innerHTML = "<?php 
                echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
                ?>
";
	window.status = "<?php 
                echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
                ?>
";
		</script>
				<?php 
                @ob_end_flush();
                // Make sure we flush the http data
            }
        }
        //while fgets
        if ($dbhandle->CompleteTrans()) {
            ?>
	<script language="JavaScript" type="text/javascript">
	document.getElementsByName("<?php 
            echo $form->prefix;
            ?>
icount")[0].innerHTML = "<?php 
            echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
            ?>
";
	window.status = "<?php 
            echo str_params(_("%1 lines processed: %2 rows"), array($nlines, $nrows), 1);
            ?>
";
		</script>
		<?php 
        } else {
            echo _("Import of data aborted.");
            echo "<br>\n";
        }
        unset($_SESSION[$form->prefix . 'importFile']);
        unset($_SESSION[$form->prefix . 'importFields']);
        unset($_SESSION[$form->prefix . 'importRnd']);
        @unlink($this->movedFile);
    }
Exemplo n.º 23
0
 public function PerformObjEdit(&$form)
 {
     $DBHandle = $form->a2billing->DBHandle();
     $oeaction = $form->getpost_single($this->fieldname . '_action');
     $oeid = $form->getpost_single($this->localkey);
     $dbg_elem = new DbgElem();
     if ($form->FG_DEBUG > 0) {
         $form->pre_elems[] =& $dbg_elem;
     }
     switch ($oeaction) {
         case 'add':
             $QUERY = str_dbparams($DBHandle, "INSERT INTO {$this->assoctable} ({$this->assocleft}, {$this->assocright}) VALUES(%1, %2);", array($oeid, $form->getpost_single($this->fieldname . '_add')));
             $dbg_elem->content .= "Query: " . htmlspecialchars($QUERY) . "\n";
             $res = $DBHandle->Execute($QUERY);
             if (!$res) {
                 $form->pre_elems[] = new ErrorElem(str_params(_("Cannot insert new %1"), array($this->fieldtitle), 1));
                 $dbg_elem->content .= "Query failed:" . $DBHandle->ErrorMsg() . "\n";
             } else {
                 $dbg_elem->content .= "Item added!";
             }
             break;
         case 'delete':
             $QUERY = str_dbparams($DBHandle, "DELETE FROM {$this->assoctable} WHERE {$this->assocleft} = %1 AND {$this->assocright} = %2;", array($oeid, $form->getpost_single($this->fieldname . '_del')));
             $dbg_elem->content .= "Query: " . htmlspecialchars($QUERY) . "\n";
             $res = $DBHandle->Execute($QUERY);
             if (!$res) {
                 $form->pre_elems[] = new ErrorElem(str_params(_("Cannot delete %1"), array($this->fieldtitle), 1));
                 $dbg_elem->content .= "Query failed: " . $DBHandle->ErrorMsg() . " \n";
             } else {
                 $dbg_elem->content .= "Item deleted!";
             }
             break;
         default:
             $dbg_elem->content .= "Unknown action {$oeaction}";
     }
     return 'ask-edit';
 }
Exemplo n.º 24
0
 /** Format and execute the Delete query */
 public function PerformAction(&$form)
 {
     $dbg_elem = new DbgElem();
     $dbhandle = $form->a2billing->DBHandle();
     if ($form->FG_DEBUG > 0) {
         array_unshift($form->pre_elems, $dbg_elem);
     }
     $del_clauses = array();
     try {
         foreach ($form->model as $fld) {
             $qc = $fld->delQueryClause($dbhandle, $form);
             if ($qc) {
                 if (is_string($qc)) {
                     $del_clauses[] = $qc;
                 } elseif (is_array($qc)) {
                     $del_clauses = array_merge($del_clauses, $qc);
                 } else {
                     throw new Exception("Why clause " . gettype($qc) . " ?");
                 }
             }
         }
     } catch (Exception $ex) {
         $form->setAction('ask-del');
         $form->pre_elems[] = new ErrorElem($ex->getMessage());
         $dbg_elem->content .= $ex->getMessage() . ' (' . $ex->getCode() . ")\n";
         // 			throw new Exception( $err_str);
     }
     $query = "DELETE FROM " . $form->model_table;
     // Protect against a nasty update!
     if (count($del_clauses) < 1) {
         $form->pre_elems[] = new ErrorElem("Cannot delete, internal error");
         $dbg_elem->content .= "Delete: no query clauses!\n";
     }
     $query .= ' WHERE ' . implode(' AND ', $del_clauses) . ';';
     $dbg_elem->content .= $query . "\n";
     /* Note: up till now, no data has been quoted/sanitized. Thus, we
        feed it direcltly to the second part of the query. Pgsql, in particular,
        can handle a binary transfer of that data to the db, in a well protected
        manner */
     if (session_readonly()) {
         $dbg_elem->content .= "Read-only: query not performed.\n";
         $form->pre_elems[] = new StringElem(_("Read only. No data has been altered."));
         $form->setAction('list');
         return;
     }
     if ($form->FG_DEBUG > 4) {
         $form->setAction('ask-del');
         $dbg_elem->content .= "Debug mode, won't delete!\n";
         return;
     }
     $res = $dbhandle->Execute($query);
     if (!$res) {
         $form->setAction('ask-del');
         $form->pre_elems[] = new ErrorElem(str_params(_("Cannot delete %1, database error."), array($form->model_name_s), 1));
         $dbg_elem->content .= $dbhandle->ErrorMsg() . "\n";
         // 			throw new Exception( $err_str);
     } elseif ($dbhandle->Affected_Rows() < 1) {
         // No result rows: update clause didn't match
         $dbg_elem->content .= ".. EOF, no rows!";
         $dbg_elem->obj = $dbhandle->Affected_Rows();
         $form->pre_elems[] = new ErrorElem(str_params(_("Cannot delete %1, record not found."), array($form->model_name_s), 1));
         $form->setAction('list');
     } else {
         $dbg_elem->content .= "Success: DELETE " . $dbhandle->Affected_Rows() . "\n";
         $form->pre_elems[] = new StringElem(_("Record successfully removed from the database."));
         $form->setAction('list');
     }
 }
Exemplo n.º 25
0
    public function Render(&$form)
    {
        $this->RenderHead();
        // For convenience, ref the dbhandle locally
        $dbhandle =& $form->a2billing->DBHandle();
        $res = $this->performQuery($form, $dbhandle);
        if (!$res) {
            return;
        }
        if ($res->EOF) {
            if ($form->list_no_records) {
                echo $list_no_records;
            } else {
                echo str_params(_("No %1 found!"), array($form->model_name_s), 1);
            }
        } else {
            $sum_res = $this->performSumQuery($form, $dbhandle);
            // now, DO render the table!
            if ($this->ncols == null) {
                $this->ncols = count($form->model);
            }
            if ($this->sum_title == null) {
                $this->sum_title = _("Sum");
            }
            ?>
	<TABLE cellPadding="2" cellSpacing="2" align='center' class="<?php 
            echo $form->list_class;
            ?>
">
		<thead><tr>
		<?php 
            foreach ($form->model as $fld) {
                if ($fld) {
                    $fld->RenderListHead($form);
                }
            }
            ?>
		</tr></thead>
		<tbody>
		<?php 
            $row_num = 0;
            while ($row = $res->fetchRow()) {
                if ($form->FG_DEBUG > 4) {
                    echo '<tr><td colspan = ' . $this->ncols . '>';
                    print_r($row);
                    echo '</td></tr>';
                }
                if ($row_num % 2) {
                    echo '<tr class="odd">';
                } else {
                    echo '<tr>';
                }
                foreach ($form->model as $fld) {
                    if ($fld) {
                        $fld->RenderListCell($row, $form);
                    }
                }
                echo "</tr>\n";
                $row_num++;
            }
            for (; $row_num < $form->list_least_rows - 1; $row_num++) {
                if ($row_num % 2) {
                    echo '<tr class="odd"></tr>';
                } else {
                    echo '<tr></tr>';
                }
            }
            ?>
			<tr class="sum"><td colspan="<?php 
            echo $this->ncols;
            ?>
" ><?php 
            echo $this->sum_title;
            ?>
</td></tr>
		<?php 
            if ($sum_res) {
                while ($row = $sum_res->fetchRow()) {
                    if ($form->FG_DEBUG > 4) {
                        echo '<tr class="sum"><td colspan = 3>';
                        print_r($row);
                        echo '</td></tr>';
                    }
                    if ($row_num % 2) {
                        echo '<tr class="sum_odd">';
                    } else {
                        echo '<tr>';
                    }
                    foreach ($form->model as $fld) {
                        if ($fld) {
                            $fld->RenderListCell($row, $form);
                        }
                    }
                    echo "</tr>\n";
                    $row_num++;
                }
            }
            ?>
		
		</tbody>
	</table>
	<?php 
            $this->RenderPages($form, $res->NumRows());
        }
        // query table
    }