Пример #1
0
 function build()
 {
     $pgParams = $this->get();
     #echo "<pre>".print_r($pgParams,true)."</pre>";
     if ($this->prep()) {
         $dbType = $this->dbType;
         $oUser = $this->oUser;
         $oPassword = $this->oPassword;
         $oHost = $this->oHost;
         $oPort = $this->oPort;
         $oOptions = $this->oOptions;
         $oCon = $this->oCon;
         $dbLimit = $this->dbLimit;
         $recTotalRows = $this->recTotalRows;
         $tblKey = $pgParams->tblKey;
         $recPage = $pgParams->recPage;
         $previousPage = $recPage - 1;
         $nextPage = $recPage + 1;
         $start = $this->dbOffset + 1;
         $end = $start + $this->dbRows - 1;
         $dbCols = $this->dbCols;
         $ignoreCols = $this->ignoreCols;
         $ignoreFilterCols = $this->ignoreFilterCols;
         $recIndex = $this->recIndex;
         $tableRows = $this->getAssociative();
         $filterableCols = $dbCols;
         for ($i = 0; $i < count($dbCols); $i++) {
             foreach ($ignoreFilterCols as $key => $value) {
                 if ($dbCols[$i]["name"] == $value) {
                     unset($filterableCols[$i]);
                 }
             }
         }
         $tableColumns = array();
         $dbColData = array();
         foreach ($dbCols as $entry) {
             $tableColumns[] = $entry["name"];
             $dbColData[$entry["name"]] = array("type" => $entry["type"]);
         }
         $tableColumnsFiltered = array_diff($tableColumns, $ignoreCols);
         if ($recTotalRows <= $dbLimit) {
             $numPages = 1;
         } else {
             if ($recTotalRows % $dbLimit == 0) {
                 $numPages = $recTotalRows / $dbLimit;
             } else {
                 $numPages = (int) ($recTotalRows / $dbLimit) + 1;
             }
         }
         $firstLink = isset($previousPage) && $previousPage > 1 ? $this->buildNav('<i class="fa fa-angle-double-left"></i>First', 1) : "";
         $lastLink = $prevLink = isset($previousPage) && $previousPage > 0 ? $this->buildNav('<i class="fa fa-angle-left"></i>Previous', $previousPage) : "";
         $nextLink = isset($nextPage) && $nextPage <= $numPages ? $this->buildNav('<i class="fa fa-angle-right"></i>Next', $nextPage) : "";
         $lastLink = isset($nextPage) && $nextPage <= $numPages ? $this->buildNav('<i class="fa fa-angle-double-right"></i>Last', $numPages) : "";
         $refreshLink = $this->buildNav('<i class="fa fa-refresh" style="margin:0"></i>', 1, 'clTblRefresh');
         if (isset($this->dbCatlog) && $this->dbCatalog != null) {
             $exportCatalog = ",'" . encrypt($this->dbType) . "'";
         } else {
             $exportCatalog = "";
         }
         $dbo = encrypt(json_encode((array) $this));
         $exportLink = '<a class="button" onclick="qry2csv(\'' . $dbo . '\' )"><i class="fa fa-download fa-fw"></i>Export</a>';
         $pageSummary = "<strong>Page</strong> " . $recPage . " of " . $numPages;
         $recordRange = "<strong>Record</strong> " . $start . " thru " . $end;
         $recordSummary = $recordRange . " | <strong>Total</strong> " . $recTotalRows;
         $filterLink = '<a class="button" onclick="arc(\'popWindowFilter\',\'/_lib/php/ArcDbFilter.php\',\'arccols=' . bin2hex(json_encode($filterableCols)) . '&arctbl=' . bin2hex(json_encode($pgParams)) . '\',1,1)"><i class="fa fa-filter fa-fw"></i>Advanced Filter</a>';
         $this->tblNav = bin2hex("\n<div id=\"" . $this->tblID . "_controlBar\" class=\"headingRow\">\n<div class=\"headingLeft\">" . $recordSummary . " | " . $pageSummary . "</div>\n<div class=\"headingRight\">" . $firstLink . $prevLink . $nextLink . $lastLink . $exportLink . $filterLink . $refreshLink . "</div>\n</div>");
         $pagingDebugValues = (object) array("recPage" => $recPage, "first" => $firstLink, "previous" => $previousPage, "nextPage" => $nextPage, "prevPage" => $previousPage, "last" => $lastLink, "numPages" => $numPages, "recTotalRows" => $recTotalRows);
         if ($this->debug === TRUE) {
             printArray($pagingDebugValues);
         }
         $dataTable = "<table class=\"dataGrid\" id=\"" . $this->tblID . "\"><tr><th>&nbsp;</th>";
         $order = $pgParams->recOrder;
         switch ($this->dbType) {
             case "mysql":
                 $strBox = array("`", "`");
                 break;
             case "mssql":
                 $strBox = array("[", "]");
                 break;
             case "pgsql":
                 $strBox = array("\"", "\"");
                 break;
         }
         $orderCol = $pgParams->recOrderCol;
         if ($this->debug === TRUE) {
             printArray($pgParams);
         }
         foreach ($tableColumnsFiltered as $record => $col) {
             if (strtolower($col) == 'action' | $col == '') {
                 $actioncol = 'class="colaction"';
                 $actioncolid = $record;
             } else {
                 $actioncol = '';
                 $actioncolid = null;
             }
             if ($orderCol == $strBox[0] . $col . $strBox[1]) {
                 if ($order == "asc") {
                     $pgParams->recPage = 1;
                     $pgParams->recOrder = "desc";
                     $sortString = '<i class="fa fa-sort-alpha-asc"></i>';
                 } else {
                     $pgParams->recPage = 1;
                     $pgParams->recOrder = "asc";
                     $sortString = '<i class="fa fa-sort-alpha-desc"></i>';
                 }
             } else {
                 $pgParams->recOrder = "asc";
                 $sortString = '<i class="fa fa-sort"></i>';
             }
             $pgParams->recOrderCol = $strBox[0] . $col . $strBox[1];
             $thtext = $col == $this->primaryKey ? '<i class="fa fa-key"></i> ' . $col : $col;
             $thdata = $actioncol == '' ? "onclick=\"arc('" . $pgParams->ajDestination . "','" . $pgParams->ajPage . "','arctbl=" . bin2hex(json_encode($pgParams)) . "',1,1)\"><div style='float:left'>" . $thtext . "</div><div style='float:right;padding-right:4px'> " . $sortString . "</div>" : ">";
             $dataTable .= "<th " . $actioncol . $thdata . "</th>";
         }
         if ($this->editable === true) {
             $dataTable .= "<th>&nbsp;</th>";
         }
         $dataTable .= "</tr>";
         foreach ($tableRows as $record) {
             $rowIndex = isset($recIndex) ? $record[$recIndex] : $start;
             if (!is_null($pgParams->recDetail)) {
                 $detailStr = $pgParams->recDetail;
                 eval("\$detail=" . $detailStr . ";");
                 $action = ' onClick="$(\'#rd' . $rowIndex . '_' . $this->tblKey . '\').toggle()"';
             } elseif (!is_null($pgParams->recLink)) {
                 $detail = "&nbsp;";
                 $action = " onClick=\"arc('" . $pgParams->actionDestination . "','" . $pgParams->recLink . "','" . $pgParams->actionFilterKey . "=" . $record[$recIndex] . "'){$pgParams->moreActions}\"";
             } else {
                 $detail = "&nbsp;";
                 $action = "";
             }
             $rowClass = $start % 2 == 0 ? "class=\"evenRow\"" : "class=\"oddRow\"";
             $dataTable .= "<tr {$rowClass} id=\"rc" . $rowIndex . "_" . $tblKey . "\">";
             $dataTable .= "<td class=\"rowID\">" . $start . "</td>";
             if ($this->editable === true) {
                 foreach ($tableColumnsFiltered as $col => $value) {
                     if ($this->elements != null) {
                         $key = multiArraySearch($this->elements, $tableColumnsFiltered[$col]);
                         $recColumn = $key !== false ? $this->elements[$key][1] : $tableColumnsFiltered[$col];
                     } else {
                         $recColumn = $tableColumnsFiltered[$col];
                     }
                     $dbColType = $dbColData[$tableColumnsFiltered[$col]]["type"];
                     $addAction = $col != $actioncolid ? $action : "";
                     $disabled = $tableColumnsFiltered[$col] == $this->primaryKey ? 'disabled=="disabed"' : '';
                     $colData = $dbColType == "text" || $dbColType == "blob" ? hex2str($record[$value]) : $record[$value];
                     switch ($dbColType) {
                         case "string":
                         case "varchar":
                         case "char":
                         case "date":
                         case "datetime":
                         case "timestamp":
                         case "time":
                             $dataTable .= "<td " . $addAction . "><input {$disabled} onblur=\"isDefault(this)\" type=\"text\" name=\"" . $recColumn . "\" value=\"" . $colData . "\"/></td>";
                             break;
                         case "int":
                         case "bigint":
                         case "numeric":
                         case "decimal":
                             $dataTable .= "<td " . $addAction . "><input {$disabled} onblur=\"isDefault(this)\" type=\"text\" name=\"" . $recColumn . "\" value=\"" . $colData . "\"/></td>";
                             break;
                         case "text":
                         case "blob":
                             $dataTable .= "<td " . $addAction . "><textarea {$disabled} onblur=\"isDefault(this)\" type=\"text\" name=\"" . $recColumn . "\">" . str_replace(">", "&gt;", str_replace("<", "&lt;", $colData)) . "</textarea></td>";
                             break;
                         default:
                             $dataTable .= "<td>Not Supported.</td>";
                             break;
                     }
                 }
             } else {
                 foreach ($tableColumnsFiltered as $col => $value) {
                     $addAction = $col != $actioncolid ? $action : "";
                     $dataTable .= "<td " . $addAction . ">" . $record[$value] . "</td>";
                 }
             }
             if ($this->editable === true) {
                 if ($this->deleteAction === null) {
                     $deleteAction = "updateRow('rc" . $rowIndex . "_" . $tblKey . "','" . $this->dbTable . "','" . $this->primaryKey . "'," . $rowIndex . ",2,'" . $this->control . "','" . $this->ajDestination . "','" . $this->actionDestination . "')";
                 } else {
                     eval("\$deleteAction = " . $this->deleteAction . ";");
                 }
                 if ($this->updateAction === null) {
                     $updateAction = "updateRow('rc" . $rowIndex . "_" . $tblKey . "','" . $this->dbTable . "','" . $this->primaryKey . "'," . $rowIndex . ",1,'" . $this->control . "','" . $this->ajDestination . "','" . $this->actionDestination . "')";
                 } else {
                     eval("\$updateAction = " . $this->updateAction . ";");
                 }
                 $dataTable .= "<td><input type=\"button\" value=\"Update\" onclick=\"" . $updateAction . "\"/><input type=\"button\" value=\"Delete\" onclick=\"" . $deleteAction . "\"/></td>";
             }
             $dataTable .= "</tr>";
             $colCount = count($tableColumnsFiltered) + 1;
             $dataTable .= "<tr class=\"rdetail\" id=\"rd" . $rowIndex . "_" . $tblKey . "\" style=\"display:none\"><td colspan=\"" . $colCount . "\" >" . $detail . "</td></tr>";
             $start = $start + 1;
         }
         $dataTable .= "</table>";
         $this->dataTable = $dataTable;
     }
 }
Пример #2
0
/** baz_gestion_formulaire() affiche le listing des formulaires et permet de les modifier
 *   @return  string    le code HTML
 */
function baz_gestion_formulaire()
{
    // la gestion des formulaires est réservée aux identifiés
    if ($GLOBALS['wiki']->GetUser()) {
        $res = '';
        if (isset($_GET['action_formulaire']) && $_GET['action_formulaire'] == 'modif') {
            // il y a un formulaire a modifier
            // recuperation des informations du type de formulaire
            $ligne = baz_valeurs_formulaire($_GET['idformulaire']);
            $formulaire = baz_formulaire_des_formulaires('modif_v');
            $formulaire->setDefaults($ligne);
            $res .= $formulaire->toHTML();
        } elseif (isset($_GET['action_formulaire']) && $_GET['action_formulaire'] == 'new') {
            // il y a un nouveau formulaire a saisir
            $formulaire = baz_formulaire_des_formulaires('new_v');
            $res .= $formulaire->toHTML();
        } elseif (isset($_GET['action_formulaire']) && $_GET['action_formulaire'] == 'new_v') {
            // il y a des donnees pour ajouter un nouveau formulaire
            $requete = 'INSERT INTO ' . BAZ_PREFIXE . 'nature (`bn_id_nature` ,`bn_ce_i18n` ,`bn_label_nature` ,`bn_template` ,`bn_description` ,`bn_condition`, `bn_label_class` ,`bn_type_fiche`)' . ' VALUES (' . baz_nextId(BAZ_PREFIXE . 'nature', 'bn_id_nature', $GLOBALS['wiki']) . ', "fr-FR", "' . addslashes(_convert($_POST['bn_label_nature'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($_POST['bn_template'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($_POST['bn_description'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($_POST['bn_condition'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($_POST['bn_label_class'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($_POST['bn_type_fiche'], TEMPLATES_DEFAULT_CHARSET, true)) . '")';
            $resultat = $GLOBALS['wiki']->query($requete);
            $res .= '<div class="alert alert-success">' . "\n" . '<a data-dismiss="alert" class="close" type="button">&times;</a>' . _t('BAZ_NOUVEAU_FORMULAIRE_ENREGISTRE') . '</div>' . "\n";
        } elseif (isset($_GET['action_formulaire']) && $_GET['action_formulaire'] == 'modif_v' && baz_a_le_droit('saisie_formulaire')) {
            //il y a des donnees pour modifier un formulaire
            $requete = 'UPDATE ' . BAZ_PREFIXE . 'nature SET `bn_label_nature`="' . addslashes(_convert($_POST['bn_label_nature'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_template`="' . addslashes(_convert($_POST['bn_template'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_description`="' . addslashes(_convert($_POST['bn_description'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_condition`="' . addslashes(_convert($_POST['bn_condition'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_label_class`="' . addslashes(_convert($_POST['bn_label_class'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_type_fiche`="' . addslashes(_convert($_POST['bn_type_fiche'], TEMPLATES_DEFAULT_CHARSET, true)) . '"' . ' WHERE `bn_id_nature`=' . $_POST['bn_id_nature'];
            $resultat = $GLOBALS['wiki']->query($requete);
            $res .= '<div class="alert alert-success">' . "\n" . '<a data-dismiss="alert" class="close" type="button">&times;</a>' . _t('BAZ_FORMULAIRE_MODIFIE') . '</div>' . "\n";
        } elseif (isset($_GET['action_formulaire']) && $_GET['action_formulaire'] == 'delete' && baz_a_le_droit('saisie_formulaire')) {
            // il y a un id de formulaire a supprimer, suppression de l'entree dans la table nature
            $requete = 'DELETE FROM ' . BAZ_PREFIXE . 'nature WHERE bn_id_nature=' . $_GET['idformulaire'];
            $resultat = $GLOBALS['wiki']->query($requete);
            //TODO : suppression des fiches associees au formulaire
            $res .= '<div class="alert alert-success">' . "\n" . '<a data-dismiss="alert" class="close" type="button">&times;</a>' . _t('BAZ_FORMULAIRE_ET_FICHES_SUPPRIMES') . '</div>' . "\n";
        }
        // affichage de la liste des templates a modifier ou supprimer
        if (!isset($_GET['action_formulaire']) || $_GET['action_formulaire'] != 'modif' && $_GET['action_formulaire'] != 'new') {
            $tab_forms['forms'] = array();
            $forms = baz_valeurs_tous_les_formulaires($GLOBALS['params']['categorienature']);
            // il y a des formulaires à importer
            if (isset($_POST['imported-form'])) {
                foreach ($_POST['imported-form'] as $id => $value) {
                    $value = json_decode($value, true);
                    $searchformname = multiArraySearch($forms, 'bn_label_nature', $value['bn_label_nature']);
                    // si un formulaire du même nom existe, on le remplace
                    if (count($searchformname) > 0) {
                        $localform = array_pop($searchformname);
                        $value['bn_id_nature'] = $localform['bn_id_nature'];
                        $requete = 'UPDATE ' . BAZ_PREFIXE . 'nature SET `bn_label_nature`="' . addslashes(_convert($value['bn_label_nature'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_template`="' . addslashes(_convert($value['bn_template'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_description`="' . addslashes(_convert($value['bn_description'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_condition`="' . addslashes(_convert($value['bn_condition'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_label_class`="' . addslashes(_convert($value['bn_label_class'], TEMPLATES_DEFAULT_CHARSET, true)) . '" ,`bn_type_fiche`="' . addslashes(_convert($value['bn_type_fiche'], TEMPLATES_DEFAULT_CHARSET, true)) . '"' . ' WHERE `bn_id_nature`=' . $value['bn_id_nature'];
                        $forms[$value['bn_type_fiche']][$value['bn_id_nature']] = $value;
                    } else {
                        // si un formulaire existant porte le meme id on enregistre un nouvel id
                        $searchformid = multiArraySearch($forms, 'bn_id_nature', $id);
                        if (count($searchformid) > 0) {
                            $id = baz_nextId(BAZ_PREFIXE . 'nature', 'bn_id_nature', $GLOBALS['wiki']);
                        }
                        $requete = 'INSERT INTO ' . BAZ_PREFIXE . 'nature (`bn_id_nature` ,`bn_ce_i18n` ,`bn_label_nature` ,`bn_template` ,`bn_description` ,`bn_condition`, `bn_label_class` ,`bn_type_fiche`)' . ' VALUES (' . $id . ', "fr-FR", "' . addslashes(_convert($value['bn_label_nature'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($value['bn_template'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($value['bn_description'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($value['bn_condition'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($value['bn_label_class'], TEMPLATES_DEFAULT_CHARSET, true)) . '", "' . addslashes(_convert($value['bn_type_fiche'], TEMPLATES_DEFAULT_CHARSET, true)) . '")';
                        // on ajoute le formulaire à la liste des formulaires existants
                        $forms[$value['bn_type_fiche']][$id] = $value;
                    }
                    $resultat = $GLOBALS['wiki']->query($requete);
                }
                ksort($forms);
                $res .= '<div class="alert alert-success">' . _t('BAZ_FORM_IMPORT_SUCCESSFULL') . '.</div>' . "\n";
            }
            foreach ($forms as $cat => $form) {
                foreach ($form as $key => $ligne) {
                    $tab_forms['forms'][$ligne['bn_id_nature']]['title'] = $ligne['bn_label_nature'];
                    $tab_forms['forms'][$ligne['bn_id_nature']]['description'] = $ligne['bn_description'];
                    $tab_forms['forms'][$ligne['bn_id_nature']]['category'] = $cat;
                    $tab_forms['forms'][$ligne['bn_id_nature']]['can_edit'] = baz_a_le_droit('saisie_formulaire');
                    $tab_forms['forms'][$ligne['bn_id_nature']]['can_delete'] = $GLOBALS['wiki']->UserIsAdmin();
                }
            }
            // on rajoute les bibliothèques js nécéssaires
            $GLOBALS['wiki']->addJavascriptFile('tools/bazar/libs/bazar.edit_forms.js');
            // On cherche un template personnalise dans le repertoire themes/tools/bazar/templates
            $templatetoload = 'themes/tools/bazar/templates/forms_table.tpl.html';
            if (!is_file($templatetoload)) {
                $templatetoload = 'tools/bazar/presentation/templates/forms_table.tpl.html';
            }
            include_once 'tools/bazar/libs/squelettephp.class.php';
            $templateforms = new SquelettePhp($templatetoload);
            $templateforms->set($tab_forms);
            $res .= $templateforms->analyser();
        }
    } else {
        $res = '<div class="alert alert-danger alert-error">' . _t('BAZ_ONLY_REGISTERED_USERS_CAN_ACCESS') . '.</div>' . "\n";
    }
    return $res;
}
Пример #3
0
$ip = new ArcDb();
$ip->dbConStr = $globalDBCON;
$ip->dbType = $globalDBTP;
$ip->dbSchema = $globalDB;
/* return all interfaces with the same address */
$ip->sql = "\nSELECT\nid_cfg_device_interface,\nid_cfg_device_ip4netaddress,\na.id_cfg_device,\na.id_device_interfacelabel,\nid_device_ifspeedduplex,\ncfg_device_interface_ip4hostaddress,\ncfg_device_interface_enabled,\nd.device,\ne.cfg,\nc.device_interfacelabel\nFROM\n_cfg_device_interface a\nINNER JOIN\n_cfg_device b \nON a.id_cfg_device=b.id_cfg_device\nINNER JOIN\n_device_interfacelabel c \nON a.id_device_interfacelabel=c.id_device_interfacelabel\nINNER JOIN\n_device d \nON b.id_device=d.id_device\nINNER JOIN\n_cfg e \nON b.id_cfg=e.id_cfg\nWHERE\ncfg_device_interface_enabled=1\nAND cfg_device_interface_ip4hostaddress=" . $_POST["cfg_device_interface_ip4hostaddress"];
$ip->getRec();
if ($ip->dbRows > 0) {
    $existingInterfaceAssignments = $ip->getAssociative();
} else {
    die('<script>prepSaveChanges("' . $_POST["form"] . '")</script>');
}
/* evaluate returned results */
if (count($existingInterfaceAssignments) > 0) {
    /* matches were found */
    /* * search array for network id passed via POST */
    $netIsDefined = multiArraySearch($existingInterfaceAssignments, $_POST["id_cfg_device_ip4netaddress"]);
    if ($netIsDefined !== false) {
        $errorMsg = long2ip($_POST["cfg_device_interface_ip4hostaddress"]) . " already exists.";
        $errorMsg .= "</br> The address is assigned to the following device interface.";
        $errorMsg .= "<pre>" . print_r($existingInterfaceAssignments[$netIsDefined], true) . "</pre>";
    } else {
        die('<script>prepSaveChanges("' . $_POST["form"] . '")</script>');
    }
}
?>
<div class="ipError">
<?php 
echo $errorMsg;
?>
</div>