Example #1
0
 public function getWidgetsList($path = "")
 {
     $prefix = "app/modules/";
     $d = dir($prefix . $path);
     $list = array();
     while (false !== ($entry = $d->read())) {
         if ($entry != "." && $entry != ".." && is_dir("{$prefix}{$path}/{$entry}")) {
             if (file_exists("{$prefix}{$path}/{$entry}/" . Application::camelize("{$path}/{$entry}", "/") . "Widget.php")) {
                 add_include_path("{$prefix}{$path}/{$entry}");
                 $widgetClass = Application::camelize("{$path}/{$entry}", "/") . "Widget";
                 $widget = new $widgetClass();
                 Application::camelize("{$path}/{$entry}");
                 $list[] = array("label" => "{$widget->label} Widget", "name" => substr("{$path}/{$entry}", 1));
             }
             $list = array_merge($list, $this->getWidgetsList("{$path}/{$entry}"));
         }
     }
     return $list;
 }
Example #2
0
add_include_path($directoryPath . "constraints", false);
add_include_path($directoryPath . "login", false);
add_include_path($directoryPath . "logout", false);
add_include_path($directoryPath . "password_history", false);
add_include_path($directoryPath . "role_validity", false);
add_include_path($directoryPath . "roles", false);
add_include_path($directoryPath . "users", false);
add_include_path($directoryPath . "users_roles", false);
//Add lib for auth
add_include_path(__DIR__ . "/lib", false);
// Load the applications configuration file and define the home
require "app/config.php";
define("SOFTWARE_HOME", $config['home']);
// Add the script which contains the third party libraries
require "app/includes.php";
// Setup the global variables needed by the redirected packages
global $redirectedPackage;
global $packageSchema;
$selected = getenv('CFX_SELECTED_DATABASE') !== false ? getenv('CFX_SELECTED_DATABASE') : $selected;
// Setup the database driver and other boilerplate stuff
$dbDriver = $config['db'][$selected]['driver'];
$dbDriverClass = Application::camelize($dbDriver);
add_include_path(Application::getWyfHome("models/datastores/databases/{$dbDriver}"));
Db::$defaultDatabase = $selected;
SQLDBDataStore::$activeDriverClass = $dbDriverClass;
Application::$config = $config;
Application::$prefix = $config['prefix'];
Cache::init($config['cache']['method']);
define('CACHE_MODELS', $config['cache']['models']);
define('CACHE_PREFIX', "");
define('ENABLE_AUDIT_TRAILS', $config['audit_trails']);
Example #3
0
 private static function _load($model, $path)
 {
     global $packageSchema;
     global $redirectedPackage;
     $model = (substr($model, 0, 1) == "." ? $redirectedPackage : "") . $model;
     $model_path = SOFTWARE_HOME . ($path == null ? Application::$packagesPath : $path) . "app/modules/" . str_replace(".", "/", $model) . "/";
     $modelClassName = Application::camelize($model) . "Model";
     add_include_path($model_path, false);
     $array = explode(".", $model);
     $model_name = array_pop($array);
     if (file_exists("{$model_path}/model.xml")) {
         if (CACHE_MODELS) {
             Cache::add("model_path_{$model}", $model_path);
         }
         $instance = XMLDefinedSQLDatabaseModel::create($model_path, $model_name, $model, $path);
         $instance->postInitHook();
     } else {
         if (file_exists("{$model_path}/{$modelClassName}.php")) {
             if (CACHE_MODELS) {
                 Cache::add("model_path_{$model}", $model_path);
             }
             $instance = new $modelClassName($model, $model_name);
             $instance->postInitHook();
         } else {
             $modelPathArray = explode(".", $model);
             $baseModelPath = SOFTWARE_HOME . ($path == null ? Application::$packagesPath : $path) . "app/modules/";
             foreach ($modelPathArray as $index => $path) {
                 $baseModelPath = $baseModelPath . "{$path}/";
                 if (file_exists($baseModelPath . "package_redirect.php")) {
                     include $baseModelPath . "package_redirect.php";
                     $modelPathArray = array_slice($modelPathArray, $index + 1);
                     $modelClassName = $package_name . Application::camelize(implode(".", $modelPathArray)) . "Model";
                     $modelIncludePath = SOFTWARE_HOME . $redirect_path . "/" . implode("/", $modelPathArray);
                     $packageSchema = $package_schema;
                     $redirectedPackage = $redirectedPackage == "" ? $package_path : $redirectedPackage;
                     add_include_path($modelIncludePath, false);
                     $instance = new $modelClassName($model, $model_name);
                     $instance->redirectedPackage = $redirectedPackage;
                     $instance->packageSchema = $packageSchema;
                     $instance->postInitHook();
                     if (CACHE_MODELS) {
                         Cache::add("model_path_{$model}", $modelIncludePath);
                     }
                 }
             }
             if ($instance == null) {
                 throw new ModelException("Failed to load Model [{$model}] with [{$modelClassName}]");
             }
         }
     }
     return $instance;
 }
Example #4
0
 /**
  * A utility method which generates camelized names for classes. It is called
  * throughout the application to convert URLs and model paths. 
  * 
  * @param string $string
  * @param string $delimiter
  * @param string $baseDelimiter
  */
 public static function camelize($string, $delimiter = ".", $baseDelimiter = "")
 {
     if ($baseDelimiter == "") {
         $baseDelimiter = $delimiter;
     }
     $parts = explode($delimiter, $string);
     $ret = "";
     foreach ($parts as $part) {
         $ret .= $delimiter == $baseDelimiter ? ucfirst(Application::camelize($part, "_", $baseDelimiter)) : ucfirst($part);
     }
     return $ret;
 }
Example #5
0
 /**
  * A utility method to load a controller. This method loads the controller
  * and fetches the contents of the controller into the Controller::$contents
  * variable if the get_contents parameter is set to true on call. If a controller
  * doesn't exist in the module path, a ModelController is loaded to help
  * manipulate the contents of the model. If no model exists in that location,
  * it is asumed to be a package and a package controller is loaded.
  *
  * @param $path         The path for the model to be loaded.
  * @param $get_contents A flag which determines whether the contents of the
  *                        controller should be displayed.
  * @return Controller
  */
 public static function load($path, $get_contents = true)
 {
     global $redirectedPackage;
     global $packageSchema;
     $controller_path = "";
     $controller_name = "";
     $redirected = false;
     $redirect_path = "";
     $package_name = "";
     $package_main = "";
     //Go through the whole path and build the folder location of the system
     for ($i = 0; $i < count($path); $i++) {
         $p = $path[$i];
         $baseClassName = $package_name . Application::camelize("{$controller_path}/{$p}", "/");
         if (file_exists(SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/{$baseClassName}Controller.php")) {
             $controller_class_name = $baseClassName . "Controller";
             $controller_name = $p;
             $controller_path .= "/{$p}";
             $controller_type = Controller::TYPE_MODULE;
             add_include_path("app/modules/{$controller_path}/");
             break;
         } else {
             if (file_exists(SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/{$p}.php")) {
                 $controller_name = $p;
                 $controller_path .= "/{$p}";
                 $controller_type = Controller::TYPE_MODULE;
                 break;
             } else {
                 if (file_exists(SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/{$baseClassName}Model.php")) {
                     $controller_name = $p;
                     $controller_path .= "/{$p}";
                     $controller_type = Controller::TYPE_MODEL;
                     break;
                 } else {
                     if (file_exists(SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/model.xml")) {
                         $controller_name = $p;
                         $controller_path .= "/{$p}";
                         $controller_type = Controller::TYPE_MODEL;
                         break;
                     } else {
                         if (file_exists(SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/report.xml")) {
                             $controller_name = $p;
                             $controller_path .= "/{$p}";
                             $controller_type = Controller::TYPE_REPORT;
                             break;
                         } else {
                             if (file_exists(SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/package_redirect.php")) {
                                 include SOFTWARE_HOME . "app/modules/{$controller_path}/{$p}/package_redirect.php";
                                 $redirected = true;
                                 $previousControllerPath = $controller_path . "/{$p}";
                                 $controller_path = "";
                                 $redirectedPackage = $package_path;
                                 $packageSchema = $package_schema;
                             } else {
                                 if ($redirected === true && file_exists(SOFTWARE_HOME . "{$redirect_path}/{$controller_path}/{$p}/report.xml")) {
                                     $controller_name = $p;
                                     $controller_path .= "/{$p}";
                                     $controller_type = Controller::TYPE_REPORT;
                                     break;
                                 } else {
                                     if ($redirected === true && file_exists(SOFTWARE_HOME . "{$redirect_path}/{$controller_path}/{$p}/{$baseClassName}Controller.php")) {
                                         $controller_class_name = $baseClassName . "Controller";
                                         $controller_name = $p;
                                         $controller_path .= "/{$p}";
                                         $controller_type = Controller::TYPE_MODULE;
                                         $package_main .= $p;
                                         add_include_path("{$redirect_path}/{$controller_path}/");
                                         break;
                                     } else {
                                         $controller_path .= "/{$p}";
                                         if ($redirected) {
                                             $package_main .= "{$p}.";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Check the type of controller and load it.
     switch ($controller_type) {
         case Controller::TYPE_MODULE:
             // Load a module controller which would be a subclass of this
             // class
             if ($controller_class_name == "") {
                 require_once SOFTWARE_HOME . "app/modules{$controller_path}/{$controller_name}.php";
                 $controller = new $controller_name();
             } else {
                 $controller_name = $controller_class_name;
                 $controller = new $controller_class_name();
                 $controller->redirected = $redirected;
                 $controller->redirectPath = $redirect_path;
                 $controller->redirectedPackage = $package_path;
                 $controller->mainRedirectedPackage = $package_main;
                 $controller->redirectedPackageName = $package_name;
             }
             break;
         case Controller::TYPE_MODEL:
             // Load the ModelController wrapper around an existing model class.
             $model = substr(str_replace("/", ".", $controller_path), 1);
             $controller_name = "ModelController";
             $controller = new ModelController($model, $package_path);
             break;
         case Controller::TYPE_REPORT:
             $controller = new XmlDefinedReportController($redirect_path . $controller_path . "/report.xml", $redirected);
             $controller_name = "XmlDefinedReportController";
             break;
         default:
             // Load a package controller for this folder
             if (is_dir("app/modules{$controller_path}")) {
                 $controller = new PackageController($path);
                 $controller_name = "PackageController";
                 $get_contents = true;
                 $force_output = true;
             } else {
                 if ($redirected === true && is_dir(SOFTWARE_HOME . "{$redirect_path}/{$controller_path}")) {
                     $controller = new PackageController($path);
                     $controller_name = "PackageController";
                     $get_contents = true;
                     $force_output = true;
                 } else {
                     $controller = new ErrorController();
                     $controller_name = "ErrorController";
                 }
             }
     }
     // If the get contents flag has been set return all the contents of this
     // controller.
     $controller->path = $previousControllerPath . $controller_path;
     if ($get_contents) {
         if ($i == count($path) - 1 || $force_output) {
             $ret = $controller->getContents();
         } else {
             if (method_exists($controller, $path[$i + 1])) {
                 $controller_class = new ReflectionClass($controller_name);
                 $method = $controller_class->GetMethod($path[$i + 1]);
                 $ret = $method->invoke($controller, array_slice($path, $i + 2));
             } else {
                 $ret = "<h2>Error</h2> Method does not exist. [" . $path[$i + 1] . "]";
             }
         }
         if (is_array($ret)) {
             $t = new TemplateEngine();
             $t->assign('controller_path', $controller_path);
             $t->assign($ret["data"]);
             $controller->content = $t->fetch(isset($ret["template"]) ? $ret["template"] : $path[$i + 1] . ".tpl");
         } else {
             if (is_string($ret)) {
                 $controller->content = $ret;
             }
         }
     }
     return $controller;
 }
Example #6
0
 /**
  * Returns the form that this controller uses to manipulate the data stored
  * in its model. As stated earlier the form is either automatically generated
  * or it is loaded from an existing file which is located in the same
  * directory as the model and bears the model's name.
  *
  * @return Form
  */
 protected function getForm()
 {
     // Load a local form if it exists.
     if ($this->redirected) {
         $formName = $this->redirectedPackageName . Application::camelize($this->mainRedirectedPackage) . "Form";
         $formPath = $this->redirectPath . "/" . str_replace(".", "/", $this->mainRedirectedPackage) . "/" . $formName . ".php";
     } else {
         $formName = Application::camelize($this->model->package) . "Form";
         $formPath = $this->localPath . "/" . $formName . ".php";
     }
     if (class_exists($formName)) {
         $form = new $formName();
     } else {
         if (is_file($formPath)) {
             include_once $formPath;
             $form = new $formName();
         } else {
             if (is_file($this->localPath . "/" . $this->name . "Form.php")) {
                 include_once $this->localPath . "/" . $this->name . "Form.php";
                 $formclass = $this->name . "Form";
                 $form = new $formclass();
             } else {
                 $form = new MCDefaultForm($this->model);
             }
         }
     }
     return $form;
 }
Example #7
0
 /**
  * Returns the form that this controller uses to manipulate the data stored
  * in its model. As stated earlier the form is either automatically generated
  * or it is loaded from an existing file which is located in the same
  * directory as the model and bears the model's name.
  *
  * @return Form
  */
 protected function getForm()
 {
     // Load a local form if it exists.
     if ($this->redirected) {
         $formName = $this->redirectedPackageName . Application::camelize($this->mainRedirectedPackage) . "Form";
         $formPath = $this->redirectPath . "/" . str_replace(".", "/", $this->mainRedirectedPackage) . "/" . $formName . ".php";
     } else {
         $formName = Application::camelize($this->model->package) . "Form";
         $formPath = $this->localPath . "/" . $formName . ".php";
     }
     if (is_file($formPath)) {
         include_once $formPath;
         $form = new $formName();
     } else {
         if (is_file($this->localPath . "/" . $this->name . "Form.php")) {
             include_once $this->localPath . "/" . $this->name . "Form.php";
             $formclass = $this->name . "Form";
             $form = new $formclass();
             $form->setModel($this->model);
         } else {
             // Generate a form automatically
             $fieldNames = array();
             $fields = $this->model->getFields();
             $form = new Form();
             $form->setModel($this->model);
             $names = array_keys($fields);
             for ($i = 0; $i < count($fields); $i++) {
                 $field = $fields[$names[$i]];
                 if ($field['key'] == 'primary') {
                     continue;
                 }
                 if ($fieldNames[$i]["renderer"] == "") {
                     if ($field["reference"] == "") {
                         switch ($field["type"]) {
                             case "boolean":
                                 $element = new Checkbox($field["label"], $field["name"], $field["description"], 1);
                                 break;
                             case "enum":
                                 $element = new SelectionList($field["label"], $field["name"]);
                                 foreach ($field["options"] as $value => $option) {
                                     $element->addOption($option, $value . "");
                                 }
                                 break;
                             case "date":
                             case "datetime":
                                 $element = new DateField($field["label"], $field["name"]);
                                 break;
                             case "integer":
                             case "double":
                                 $element = new TextField($field["label"], $field["name"], $field["description"]);
                                 $element->setAsNumeric();
                                 break;
                             case "textarea":
                                 $element = new TextArea($field["label"], $field["name"], $field["description"]);
                                 break;
                             default:
                                 $element = new TextField($field["label"], $field["name"], $field["description"]);
                                 break;
                         }
                     } else {
                         $element = new ModelField($field["reference"], $field["referenceValue"]);
                     }
                     foreach ($field["validators"] as $validator) {
                         switch ($validator["type"]) {
                             case "required":
                                 $element->setRequired(true);
                                 break;
                             case "unique":
                                 $element->setUnique(true);
                                 break;
                             case "regexp":
                                 $element->setRegexp((string) $validator["parameter"]);
                                 break;
                         }
                     }
                 } else {
                     $renderer = (string) $fieldNames[$i]["renderer"];
                     $element = new $renderer();
                 }
                 $form->add($element);
             }
             $form->addAttribute("style", "width:50%");
             $form->useAjax(true, false);
         }
     }
     return $form;
 }
Example #8
0
 private static function getNestedModelInstance($model, $path, $modelName)
 {
     global $packageSchema;
     $modelPathArray = explode(".", $model);
     $baseModelPath = SOFTWARE_HOME . ($path == null ? Application::$packagesPath : $path) . "app/modules/";
     foreach ($modelPathArray as $index => $path) {
         $baseModelPath = $baseModelPath . "{$path}/";
         if (file_exists($baseModelPath . "package_redirect.php")) {
             include $baseModelPath . "package_redirect.php";
             $modelPathArray = array_slice($modelPathArray, $index + 1);
             $modelClassName = $package_name . Application::camelize(implode(".", $modelPathArray)) . "Model";
             $modelIncludePath = SOFTWARE_HOME . $redirect_path . "/" . implode("/", $modelPathArray);
             $packageSchema = $package_schema;
             $redirectedPackage = $redirectedPackage == "" ? $package_path : $redirectedPackage;
             add_include_path($modelIncludePath, false);
             $instance = new $modelClassName($model, $modelName);
             $instance->postInitHook();
             Cache::add("model_path_{$model}", $modelIncludePath);
         }
     }
     if ($instance == null) {
         throw new ModelException("Failed to load Model [{$model}] with [{$modelClassName}]");
     }
     return $instance;
 }
Example #9
0
 private function getFormDetails()
 {
     if ($this->redirected) {
         $formName = $this->redirectedPackageName . Application::camelize($this->mainRedirectedPackage) . "Form";
         $formPath = $this->redirectPath . "/" . str_replace(".", "/", $this->mainRedirectedPackage) . "/" . $formName . ".php";
     } else {
         $formName = Application::camelize($this->model->package) . "Form";
         $formPath = $this->localPath . "/" . $formName . ".php";
     }
     return array('path' => $formPath, 'name' => $formName);
 }