/** * @param string $url * @param string $url2 */ public function index($url = "", $url2 = "") { if (Tools::isPost('submitDBConfigBtn')) { $db_provider = 'mysql'; $db_host = Tools::post('db_host'); $db_username = Tools::post('db_username'); $db_password = Tools::post('db_password'); $db_name = Tools::post('db_name'); $dbError = false; $DB = NewADOConnection($db_provider); try { $DB->Connect($db_host, $db_username, $db_password, $db_name); } catch (ErrorException $e) { $dbError = true; } $result = $DB->Execute("Show tables;"); $errorMsg = $DB->ErrorMsg(); if ($result === false || $dbError === true || $errorMsg != "") { FlashSession::setFlash('error', $errorMsg); } else { $DB->Close(); $dbAccess = new DBAccess(); $dbAccess->setDbUsername($db_username); $dbAccess->setDbPassword($db_password); $dbAccess->setDbHost($db_host); $dbAccess->setDbName($db_name); Session::set('dbAccess', $dbAccess); Session::set('dbConfigured', true); if ($url != "") { $url = $url2 == "" ? $url2 : $url . "/" . $url2; Tools::redirect($url); } else { Tools::redirect('home'); } } } $this->view->render('dbconfig/index'); }
<div class="main-div-index"> <form action="" id="export_form" class="form-horizontal export-step" method="post"> <fieldset> <legend>Export to CSV</legend> <?php FlashSession::showSuccess(); FlashSession::showErrors(); ?> <div class="control-group"> <label class="control-label" for="exported_table_csv">Select Table <i class="icon-th-large"></i></label> <div class="controls"> <select name="exported_table_csv" id="exported_table_csv" required="required"> <option value=""> </option> <?php foreach ($this->tableList as $table) { echo '<option value="' . $table . '">' . $table . '</option>'; } ?> </select> </div> </div> <div id="field-list-div" class="control-group"> </div> </div>
public function checkExportPDFForm() { $tableName = Tools::post('exported_table_pdf'); $fieldsList = Tools::post('exported_fields'); $pdf_file_name = Tools::post('pdf_file_name'); $aError = array(); if ($tableName == "") { $aError[] = "You must choose Table Name !"; } if (count($fieldsList) == 0) { $aError[] = "You must choose at least one column !"; } if ($pdf_file_name == "") { $aError[] = "You must output File name!"; } /* * Check Errors * */ if (count($aError) == 0) { return true; } else { FlashSession::setFlash('error', implode('<br>', $aError)); return false; } }
public function importExcelTable() { $tableName = $this->input->post('imported_table_xls'); $fieldsList = $this->input->post('imported_fields'); $headerRow = $this->input->post('with_header_row'); $updateQuery = $this->input->post('update_query'); $objPHPExcel = PHPExcel_IOFactory::load($_FILES['xls_file']['tmp_name']); $objWorksheet = $objPHPExcel->getActiveSheet(); $cp = 1; $aSql = array(); $totalQuery = 0; foreach ($objWorksheet->getRowIterator() as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells, if ($headerRow && $cp++ == 1) { continue; } $aLine = array(); $aUpdateQuery = array(); $cTmp = 0; foreach ($cellIterator as $cell) { $valueCell = IMPORT_ENCODE_FUNCTION != "none" && function_exists(IMPORT_ENCODE_FUNCTION) ? call_user_func(IMPORT_ENCODE_FUNCTION, $cell->getValue()) : $cell->getValue(); $valueCell = mysql_real_escape_string($valueCell); $aLine[] = $valueCell; if (isset($fieldsList[$cTmp])) { $aUpdateQuery[] = $fieldsList[$cTmp] . " = '$valueCell' "; } $cTmp++; } if ($updateQuery == "1") { $sql = "UPDATE $tableName "; $sql .= "SET " . implode(',', $aUpdateQuery); $sql .= "WHERE " . $fieldsList[0] . "='" . $aLine[0] . "' ; "; $this->DB->Execute($sql); $totalQuery++; } else { $aSql[] = "('" . implode("','", $aLine) . "')"; } } if ($updateQuery == "0" && count($aSql) > 0) { $sql = "INSERT INTO $tableName (" . implode(",", $fieldsList) . ") VALUES "; $sql .= implode(',', $aSql); $this->DB->Execute($sql); $totalQuery = count($aSql); $queryMessage = ' rows imported.'; } else { $queryMessage = ' rows updated.'; } $errorMsg = $this->DB->ErrorMsg(); if ($errorMsg != "") { FlashSession::setFlash('error', $errorMsg); } else { FlashSession::setFlash('success', 'Import has been successfully finished : ' . $totalQuery . $queryMessage); } }
public function excel() { if (Tools::isPost('submitImportTable')) { if ($this->checkImportExcelForm()) { /** @var Import_Model $this->model */ $this->import->importExcelTable(); } } if (Session::get('dbConfigured')) { $this->view->tableList = $this->import->getTablesList(); $this->load->view('import/excel/index'); } else { FlashSession::setFlash('error', 'You must configure your Database before Importing tables'); Tools::redirect('dbconfig/index/import/excel'); } }
public function exportCustomPDF() { $custom_query = Tools::post('custom_query'); $headerRow = Tools::post('with_header_row'); $pdf_file_name = Tools::post('pdf_file_name'); $this->DB->SetFetchMode(ADODB_FETCH_ASSOC); $result = $this->DB->Execute($custom_query); $errorMsg = $this->DB->ErrorMsg(); if ($errorMsg != "") { FlashSession::setFlash('error', $errorMsg); return false; } FileManager::downloadPDFFile($result, $headerRow, $pdf_file_name); }
/** * @return bool */ function processLogin() { global $cAdminAccess; $username = $_POST['username']; $password = $_POST['password']; if ($username == $cAdminAccess['admin_login'] && $password == $cAdminAccess['admin_password']) { Session::set(ADMIN_SESSION_NAME, $username); return true; } else { FlashSession::setFlash('error', 'Invalid Username or Password !'); return false; } }