* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ require_once "Libs/autoload.php"; $auth = new Auth(); if (!$auth->isAuthorized()) { $auth->forbidden(); exit(0); // Should never get here but just in case... } $result = "OK"; $id = Tools::param('id'); $mode = Tools::param('mode'); $rowStyle = Tools::param('rowStyle'); $html = ''; $companyListView = new CompanyListView('html', null); if ('add' == $mode) { $companyModel = new CompanyModel(); $companyModel->setId($id); $htmlRows = $companyListView->displayCompanyRow($companyModel, $mode, $rowStyle); } else { $companyController = new CompanyController(); $companyModel = $companyController->get($id); $htmlRows = $companyListView->displayCompanyRow($companyModel, $mode, $rowStyle); } $result = array('result' => $result, 'rows' => $htmlRows); echo json_encode($result) . PHP_EOL;
public function getSome($whereClause = '1 = 1') { $sql = <<<SQL SELECT id , agencyCompanyId , companyName , companyAddress1 , companyAddress2 , companyCity , companyState , companyZip , companyPhone , companyUrl , created , updated FROM company WHERE {$whereClause} ORDER BY companyName SQL; $stmt = $this->_dbh->prepare($sql); if (!$stmt) { throw new ControllerException('Failed to prepare SELECT statement. (' . $this->_dbh->error . ')'); } if (!$stmt->execute()) { throw new ControllerException('Failed to execute SELECT statement. (' . $this->_dbh->error . ')'); } if (!$stmt->bind_result($id, $agencyCompanyId, $companyName, $companyAddress1, $companyAddress2, $companyCity, $companyState, $companyZip, $companyPhone, $companyUrl, $created, $updated)) { throw new ControllerException('Failed to bind to result: (' . $this->_dbh->error . ')'); } $models = array(); while ($stmt->fetch()) { $model = new CompanyModel(); $model->setId($id); $model->setAgencyCompanyId($agencyCompanyId); $model->setCompanyName($companyName); $model->setCompanyAddress1($companyAddress1); $model->setCompanyAddress2($companyAddress2); $model->setCompanyCity($companyCity); $model->setCompanyState($companyState); $model->setCompanyZip($companyZip); $model->setCompanyPhone($companyPhone); $model->setCompanyUrl($companyUrl); $model->setCreated($created); $model->setUpdated($updated); $models[] = $model; } return $models; }