public function sharedResponse()
 {
     if (!isset(self::$shared_response)) {
         self::$shared_response = new ControllerResponse();
     }
     return self::$shared_response;
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     $this->table->addOperation('roles', "Add Role(s)");
     $this->table->addOperation('reset_password', "Reset Password");
     $this->table->addOperation('disable_user', "Disable User", "javascript:wyf.confirmRedirect('Are you sure you want to disable user?','{$this->urlPath}/%path%/%key%')");
 }
 public function getContents()
 {
     $ret = parent::getContents();
     if ($this->apiMode === false) {
         $ret .= "<script type='text/javascript'>\n                    wyf.updateFilter('{$this->table->name}', '{$this->filterFieldModel->database}.{$this->filterField}', '{$this->defaultValue}');\n                    {$this->table->name}Search();\n                </script>";
     }
     return $ret;
 }
 public function getContents()
 {
     $ret = parent::getContents();
     foreach ($this->selectionLists as $list) {
         if ($this->apiMode === false) {
             $ret .= "<script type='text/javascript'>\n                    wyf.updateFilter('{$this->table->name}', '{$this->filterFieldModel->database}.{$list['filter_field']}', '{$list['default_value']}');\n                    {$this->table->name}Search();\n                </script>";
         }
     }
     return $ret;
 }
Example #5
0
 public function getImporterForm()
 {
     $key = $this->parentController->model->getKeyField();
     $form = parent::getForm();
     $list = Element::create('SelectionList', Utils::singular($this->parentController->model->getEntity()), $key);
     $items = $this->parentController->model->get();
     foreach ($items as $item) {
         $this->parentController->model->setData($item);
         $list->addOption((string) $this->parentController->model, $item[$key]);
     }
     $form->add($list);
     return $form;
 }
Example #6
0
/**
 * Created by PhpStorm.
 * User: roessler
 * Date: 16/09/15
 * Time: 1:22 PM
 */
/**
 * Backend page for administrators and Staff of Cyril's Classic Cars to add and view models
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'config/config.php';
if (isset($_SESSION['authenticated'])) {
    if ($_SESSION['authenticated'] == true) {
        $addResult = null;
        $makeCon = new MakeController();
        $modelCon = new ModelController();
        if (isset($_POST['hdnAction'])) {
            if ($_POST['hdnAction'] == 'insert') {
                $result = $modelCon->insertModel($_POST['txtModelName'], $_POST['txtMakeId']);
                if ($result->errorInfo()[2] == null) {
                    $addResult = true;
                } else {
                    $addResult = $result->errorInfo()[2];
                }
            }
        }
        ?>
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="utf-8">
<?php

/**
 * Created by PhpStorm.
 * User: roessler
 * Date: 9/18/15
 * Time: 12:12 PM
 */
/**
 * Home Page for Cyril's Classic Cars
 */
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$makeCon = new MakeController();
$modelCon = new ModelController();
$carCon = new CarController();
$featureCon = new FeatureController();
$mediaCon = new MediaController();
function dollar_format($value)
{
    $value = floatval($value);
    return '$' . number_format($value, 2);
}
function checkSelected($val1, $val2)
{
    if ($val1 == $val2) {
        echo 'selected';
    }
}
function checkFeatures($val, $features)
{
    if (in_array($val, $features)) {
Example #8
0
/**
 * Created by PhpStorm.
 * User: roessler
 * Date: 16/09/15
 * Time: 1:22 PM
 */
/**
 * Backend page for administrators and Staff of Cyril's Classic Cars to add and view models
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'config/config.php';
if (isset($_SESSION['authenticated'])) {
    if ($_SESSION['authenticated'] == true) {
        $addResult = null;
        $makeCon = new MakeController();
        $modelCon = new ModelController();
        $carCon = new CarController();
        if (isset($_POST['hdnAction'])) {
            if ($_POST['hdnAction'] == 'insert') {
                $result = $carCon->insertCar($_POST['txtRego'], $_POST['txtBodyType'], $_POST['txtTransmission'], $_POST['txtDriveType'], $_POST['txtFuelType'], $_POST['txtYear'], $_POST['txtOdometer'], $_POST['txtColour'], $_POST['txtDoors'], $_POST['txtSeats'], $_POST['txtEngineSize'], $_POST['txtCylinders'], $_POST['txtModelId']);
                if ($result->errorInfo()[2] == null) {
                    $addResult = true;
                } else {
                    $addResult = $result->errorInfo()[2];
                }
            }
        }
        ?>
        <!DOCTYPE html>
        <html lang="en">
        <head>
Example #9
0
 public function __construct()
 {
     parent::__construct("common.roles");
     $this->table->addOperation("permissions", "Permissions");
     //$this->table->addOperation("constraints", "Set Constraints");
 }
Example #10
0
 $rego = null;
 $bodyType = null;
 $transmission = null;
 $driveType = null;
 $fuelType = null;
 $year = null;
 $odometer = null;
 $colour = null;
 $doors = null;
 $seats = null;
 $engineSize = null;
 $cylinders = null;
 $modelId = null;
 $makeId = null;
 $carCon = new CarController();
 $modelCon = new ModelController();
 $makeCon = new MakeController();
 function checkSelected($id1, $id2)
 {
     if ($id1 == $id2) {
         echo 'selected';
     }
 }
 if (isset($_GET['id'])) {
     $carId = $_GET['id'];
     $car = $carCon->getCar($carId);
     if ($car->errorInfo()[2] == null) {
         $row = $car->fetch();
         $rowCount = count($row);
         if ($rowCount > 0) {
             $model = $modelCon->getModel($row['model_id']);
Example #11
0
 public function __construct()
 {
     parent::__construct(".users");
     $this->table->addOperation('reset', "Reset Password");
 }
Example #12
0
<?php

/**
 * Created by PhpStorm.
 * User: roessler
 * Date: 9/20/15
 * Time: 10:55 AM
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'config/config.php';
if (isset($_POST['txtMakeId'])) {
    $modelCon = new ModelController();
    $models = $modelCon->getModelsInMake($_POST['txtMakeId']);
    if ($models->errorInfo()[2] == null) {
        $rows = $models->fetchAll();
        $rowCount = count($rows);
        if ($rowCount > 0) {
            $modelResults = array();
            foreach ($rows as $row) {
                $modelResults[$row['model_id']] = $row['model_name'];
            }
        }
        $modelObject = json_encode($modelResults);
        print_r($modelObject);
        return $modelObject;
    }
}
Example #13
0
<?php

/* global $app */
// note-fields: title, content, trash, create_date, group_id, note_id
// group-fields: id, name, trash
// $model = new ModelController2(new NotePrototype, new GroupPrototype, new JSONController());
// $model = new ModelController2(new NotePrototype, new GroupPrototype, new MySQLController());
// $model = new ModelController(new JSONController(), new DataHelper(), new Validator());
$model = new ModelController(new MySQLController(), new DataHelper(), new Validator());
$app->group('/api', function () use($app, $model) {
    $app->group('/todos', function () use($app, $model) {
        $app->get('/', function ($req, $res, $arg) use($model) {
            $res->getBody()->write(json_encode($model->showNotes()));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->get('/{id:[0-9]+}', function ($req, $res, $arg) use($model) {
            $res->getBody()->write(json_encode($model->showNote($arg['id'])));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->post('/', function ($req, $res, $arg) use($model) {
            $status = $model->createNote($req->getParams());
            $res->getBody()->write(json_encode(array('status' => $status == 0 ? false : true)));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->put('/{id:[0-9]+}', function ($req, $res, $arg) use($model) {
            $res->getBody()->write(json_encode(array('status' => $model->editNote(json_decode($req->getBody(), true)))));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
 /**
  * Returns the filters for this controller. In addition to parent filters 
  * we want access control.
  * @return array
  */
 public function filters()
 {
     return array_merge(parent::filters(), array('accessControl'));
 }
Example #15
0
    public function printCars()
    {
        $cars = $this->getCars();
        $makeCon = new MakeController();
        $modelCon = new ModelController();
        if ($cars->errorInfo()[2] == null) {
            $rows = $cars->fetchAll();
            $rowCount = count($rows);
            if ($rowCount > 0) {
                ?>
                <table class="table table-responsive table-hover">
                    <tr>
                        <th>Make Name</th><th>Model Name</th><th>Year</th><th>Body Type</th><th>Registration Number</th><th>Actions</th>
                    </tr>
                    <?php 
                foreach ($rows as $row) {
                    $model = $modelCon->getModel($row['model_id']);
                    $model = $model->fetch();
                    $make = $makeCon->getMake($model['make_id']);
                    $make = $make->fetch();
                    ?>
                        <tr>
                            <td><?php 
                    echo $make['make_name'];
                    ?>
</td><td><?php 
                    echo $model['model_name'];
                    ?>
</td><td><?php 
                    echo $row['year'];
                    ?>
</td><td><?php 
                    echo $row['body_type'];
                    ?>
</td><td><?php 
                    echo $row['rego_number'];
                    ?>
</td>
                            <td><a href="./view.php?id=<?php 
                    echo $row['car_id'];
                    ?>
" class="btn btn-info"><span class="glyphicon glyphicon-briefcase"></span> View</a> <a href="./edit.php?id=<?php 
                    echo $row['car_id'];
                    ?>
" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span> Edit</a> <a href="./delete.php?id=<?php 
                    echo $row['car_id'];
                    ?>
" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Delete</a></td>
                        </tr>
                    <?php 
                }
                ?>
                </table>
            <?php 
            } else {
                ?>
                <div class="alert alert-info" role="alert">
                    <strong>No results.</strong> There are no cars to display<br/>
                    Use the form above to add some.
                </div>
            <?php 
            }
        } else {
            ?>
            <div class="alert alert-danger" role="alert">
                <strong>Uh oh!</strong> The database returned the following error:<br/>
                <em><?php 
            echo $cars->errorInfo()[2];
            ?>
</em>
            </div>
        <?php 
        }
        $cars->closeCursor();
    }
 /**
  * todo: docs
  *
  * @param Parser $parser
  *
  * @endpoint ignore
  * @return array
  */
 public function getDocJSON(Parser $parser)
 {
     $doc = parent::getDocJSON($parser);
     $rClass = new \ReflectionClass(get_called_class());
     foreach ($doc['methods'] as $k => $methodDoc) {
         if ($methodDoc['InternalMethodName'] == 'get') {
             $doc['methods'][$k]['MethodName'] = 'Get Full Collection';
         } elseif ($methodDoc['InternalMethodName'] == 'post') {
             $doc['methods'][$k]['MethodName'] = 'Add to Collection';
         } elseif ($methodDoc['InternalMethodName'] == 'put') {
             $doc['methods'][$k]['MethodName'] = 'Replace Full Collection';
         } elseif ($methodDoc['InternalMethodName'] == 'delete') {
             $doc['methods'][$k]['MethodName'] = 'Delete Full Collection';
         }
     }
     $methodDoc = $this->getRestMethodDocJSON($parser, 'Get Resource', 'GET', "/{$this->base}/:id", $rClass, '_restGetResource');
     if (!empty($methodDoc)) {
         $doc['methods'][] = $methodDoc;
     }
     $methodDoc = $this->getRestMethodDocJSON($parser, 'Update Resource', 'PUT', "/{$this->base}/:id", $rClass, '_restPutResource');
     if (!empty($methodDoc)) {
         $doc['methods'][] = $methodDoc;
     }
     $methodDoc = $this->getRestMethodDocJSON($parser, 'Delete Resource', 'DELETE', "/{$this->base}/:id", $rClass, '_restDeleteResource');
     if (!empty($methodDoc)) {
         $doc['methods'][] = $methodDoc;
     }
     // Add documentation for custom rest actions
     $rMethods = $rClass->getMethods(\ReflectionMethod::IS_PUBLIC);
     foreach ($rMethods as $rMethod) {
         $docComment = $rMethod->getDocComment();
         // If there is a '@endpoint ignore' property, the function is not served as an endpoint
         if (in_array('ignore', ReflectionHelper::getDocDirective($docComment, 'endpoint'))) {
             continue;
         }
         $methodDoc = array();
         $methodDoc['InternalMethodName'] = $rMethod->name;
         if (strpos($rMethod->name, 'restGet', 0) === 0) {
             $methodDoc['MethodName'] = substr($rMethod->name, 7);
             $methodDoc['HTTPMethod'] = 'GET';
         } elseif (strpos($rMethod->name, 'restPut', 0) === 0) {
             $methodDoc['MethodName'] = substr($rMethod->name, 7);
             $methodDoc['HTTPMethod'] = 'PUT';
         } elseif (strpos($rMethod->name, 'restPost', 0) === 0) {
             $methodDoc['MethodName'] = substr($rMethod->name, 8);
             $methodDoc['HTTPMethod'] = 'POST';
         } elseif (strpos($rMethod->name, 'restDelete', 0) === 0) {
             $methodDoc['MethodName'] = substr($rMethod->name, 10);
             $methodDoc['HTTPMethod'] = 'DELETE';
         } else {
             continue;
         }
         $action = strtolower($methodDoc['MethodName']);
         $methodDoc['URI'] = "/{$this->base}/:id/{$action}";
         $methodDoc['Synopsis'] = $parser->parse(ReflectionHelper::getDocText($docComment));
         $methodDoc['parameters'][] = array('Name' => 'id', 'Required' => 'Y', 'Type' => 'string', 'Location' => 'url', 'Description' => 'The id of the resource');
         $methodDoc['parameters'] = array_merge($methodDoc['parameters'], $this->getDocParameters($rMethod));
         // Allow controller middlewares to modify the documentation for this method
         if (!empty($this->middlewares)) {
             $middleware = reset($this->middlewares);
             $middleware->documentMethod($rClass, $rMethod, $methodDoc);
         }
         if (!empty($methodDoc)) {
             $doc['methods'][] = $methodDoc;
         }
     }
     return $doc;
 }
Example #17
0
 * Created by PhpStorm.
 * User: roessler
 * Date: 16/09/15
 * Time: 1:22 PM
 */
/**
 * Backend page for administrators and Staff of Cyril's Classic Cars to delete models
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'config/config.php';
if (isset($_SESSION['authenticated'])) {
    if ($_SESSION['authenticated'] == true) {
        $deleteResult = null;
        $modelId = null;
        $modelName = null;
        $makeId = null;
        $modelCon = new ModelController();
        $makeCon = new MakeController();
        function checkSelected($id1, $id2)
        {
            if ($id1 == $id2) {
                echo 'selected';
            }
        }
        if (isset($_GET['id'])) {
            $modelId = $_GET['id'];
            $model = $modelCon->getModel($modelId);
            if ($model->errorInfo()[2] == null) {
                $row = $model->fetch();
                $rowCount = count($row);
                if ($rowCount = 1) {
                    $modelName = $row['model_name'];
Example #18
0
 * Created by PhpStorm.
 * User: roessler
 * Date: 16/09/15
 * Time: 1:22 PM
 */
/**
 * Backend page for administrators and Staff of Cyril's Classic Cars to edit models
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'config/config.php';
if (isset($_SESSION['authenticated'])) {
    if ($_SESSION['authenticated'] == true) {
        $editResult = null;
        $modelId = null;
        $modelName = null;
        $makeId = null;
        $modelCon = new ModelController();
        $makeCon = new MakeController();
        function checkSelected($id1, $id2)
        {
            if ($id1 == $id2) {
                echo 'selected';
            }
        }
        if (isset($_GET['id'])) {
            $modelId = $_GET['id'];
            $model = $modelCon->getModel($modelId);
            if ($model->errorInfo()[2] == null) {
                $row = $model->fetch();
                $rowCount = count($row);
                if ($rowCount = 1) {
                    $modelName = $row['model_name'];
Example #19
0
 public function getForm()
 {
     $form = parent::getForm();
     $form->add(Element::create('HiddenField', $this->parentController->model->getKeyField(), $this->parentItemId));
     return $form;
 }
Example #20
0
 /**
  * The callback used by the form class. This callback is only called when
  * the add or edit controller actions are performed. 
  * 
  * @param array $data The data from the form
  * @param Form $form an instance of the form
  * @param mixed $c Specific data from the form, this normally includes an instance of the controller
  * @param boolean $redirect If true the controller redirects the page after execution
  * @see ModelController::$callbackFunction
  * @return boolean
  */
 public static function callback($data, &$form, $c, $redirect = true, &$id = null)
 {
     switch ($c["action"]) {
         case "add":
             $return = $c["instance"]->model->setData($data);
             if ($return === true) {
                 $id = $c["instance"]->model->save();
                 User::log($c["success_message"], $data);
                 if ($redirect) {
                     Application::redirect($c["instance"]->urlPath . "?notification=" . urlencode($c["success_message"]));
                 } else {
                     return true;
                 }
             } else {
                 $fields = array_keys($return["errors"]);
                 foreach ($fields as $field) {
                     foreach ($return["errors"][$field] as $error) {
                         $element = $c["form"]->getElementByName($field);
                         $element->addError(str_replace("%field_name%", $element->getLabel(), $error));
                     }
                 }
                 foreach ($return['errors'] as $fieldName => $error) {
                     $form->addError(str_replace("%field_name%", str_replace('_', ' ', $fieldName), $error));
                 }
             }
             break;
         case "edit":
             $return = $c["instance"]->model->setData($data, $c["key_field"], $c["key_value"]);
             if ($return === true) {
                 $c["instance"]->model->update($c["key_field"], $c["key_value"]);
                 User::log($c["success_message"], $data);
                 if ($redirect) {
                     Application::redirect($c["instance"]->urlPath . "?notification=" . urlencode($c["success_message"]));
                 } else {
                     return true;
                 }
             } else {
                 $fields = array_keys($return["errors"]);
                 self::$pendingErrors = $return['errors'];
                 foreach ($fields as $field) {
                     foreach ($return["errors"][$field] as $error) {
                         $element = $c["form"]->getElementByName($field);
                         $element->addError(str_replace("%field_name%", $element->getLabel(), $error));
                     }
                 }
                 foreach ($return['errors'] as $fieldName => $error) {
                     $form->addError(str_replace("%field_name%", str_replace('_', ' ', $fieldName), $error));
                 }
             }
             break;
     }
 }
Example #21
0
 public function __construct()
 {
     parent::__construct(".roles");
     $this->table->addOperation("permissions", "Permissions");
 }
Example #22
0
             }
             $modelObject = json_encode($modelResults);
         } else {
             $modelObject = null;
         }
         print_r($modelObject);
         return $modelObject;
     }
 } else {
     $makeCon = new MakeController();
     $make = $makeCon->getMakeByName($_POST['txtMake']);
     if ($make->errorInfo()[2] == null) {
         $make = $make->fetch();
         if (count($make) > 0) {
             $makeId = $make['make_id'];
             $modelCon = new ModelController();
             $models = $modelCon->getModelsInMake($makeId);
             if ($models->errorInfo()[2] == null) {
                 $rows = $models->fetchAll();
                 $rowCount = count($rows);
                 if ($rowCount > 0) {
                     $modelResults = array();
                     foreach ($rows as $row) {
                         $modelResults[$row['model_name']] = $row['model_name'];
                     }
                     $modelObject = json_encode($modelResults);
                 } else {
                     $models = $modelCon->getModels();
                     if ($models->errorInfo()[2] == null) {
                         $rows = $models->fetchAll();
                         $rowCount = count($rows);
Example #23
0
 * Backend page for administrators and Staff of Cyril's Classic Employees to edit employees
 */
require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'config/config.php';
if (isset($_SESSION['authenticated'])) {
    if ($_SESSION['authenticated'] == true) {
        $editResult = null;
        $sellerCon = new SellerController();
        $custCon = new CustomerController();
        $personCon = new PersonController();
        $offerCon = new OfferController();
        $featureCon = new FeatureController();
        $foCon = new Feature_OfferController();
        $mediaCon = new MediaController();
        $carCon = new CarController();
        $makeCon = new MakeController();
        $modelCon = new ModelController();
        $saleCon = new SaleController();
        $empCon = new EmployeeController();
        $saleId = null;
        $offerId = null;
        $buyerId = null;
        $empId = null;
        $carId = null;
        $sellerName = null;
        $preferredPrice = null;
        $makeName = null;
        $modelName = null;
        $year = null;
        $rego = null;
        $description = null;
        $features = array();
Example #24
0
 /**
  * The callback used by the form class. This callback is only called when
  * the add or edit controller actions are performed. 
  * 
  * @param array $data The data from the form
  * @param Form $form an instance of the form
  * @param \ModelController $instance Specific data from the form, this normally includes an instance of the controller
  * 
  * @see ModelController::$callbackFunction
  * @return boolean
  */
 public static function callback($data, $form, $instance)
 {
     $key = $instance->model->getKeyField();
     $return = $instance->model->setData($data, $key, $instance->currentItemId);
     $entity = Utils::singular($instance->model->getEntity());
     if ($return === true) {
         if ($instance->actionMethod === 'add') {
             $id = $instance->model->save();
             Application::queueNotification($instance->getAddNotificationMessage($entity, $instance->model));
         } else {
             $id = $instance->model->update($key, $instance->currentItemId);
             Application::queueNotification($instance->getUpdateNotificationMessage($entity, $instance->model));
         }
         Application::redirect($instance->urlPath);
     } else {
         self::setFormErrors($form, $return['errors']);
     }
 }