Example #1
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * 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');
$html = '';
$contactListView = new ContactListView('html', null);
if ('add' == $mode) {
    $contactModel = new ContactModel();
    $contactModel->setId($id);
    $html = $contactListView->displayContactRow($contactModel, $mode);
} else {
    $contactController = new ContactController();
    $contactModel = $contactController->get($id);
    $html = $contactListView->displayContactRow($contactModel, $mode);
}
$result = array('result' => $result, 'row' => $html);
echo json_encode($result) . PHP_EOL;
Example #2
0
    /**
     * @see ControllerBase::getSome()
     */
    public function getSome($whereClause = '1 = 1')
    {
        $sql = <<<SQL
SELECT id
     , contactCompanyId
     , contactName
     , contactEmail
     , contactPhone
     , contactAlternatePhone
     , created
     , updated
  FROM contact
 WHERE {$whereClause}
 ORDER
    BY contactName
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 . ')');
        }
        $stmt->bind_result($id, $contactCompanyId, $contactName, $contactEmail, $contactPhone, $contactAlternatePhone, $created, $updated);
        $models = array();
        while ($stmt->fetch()) {
            $model = new ContactModel();
            $model->setId($id);
            $model->setContactCompanyId($contactCompanyId);
            $model->setContactName($contactName);
            $model->setContactEmail($contactEmail);
            $model->setContactPhone($contactPhone);
            $model->setContactAlternatePhone($contactAlternatePhone);
            $model->setCreated($created);
            $model->setUpdated($updated);
            $models[] = $model;
        }
        return $models;
    }