diff options
Diffstat (limited to 'lib/prado/framework/Wsat')
20 files changed, 1151 insertions, 0 deletions
diff --git a/lib/prado/framework/Wsat/TWsatARGenerator.php b/lib/prado/framework/Wsat/TWsatARGenerator.php new file mode 100644 index 0000000..a576b21 --- /dev/null +++ b/lib/prado/framework/Wsat/TWsatARGenerator.php @@ -0,0 +1,240 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package System.Wsat + */ +Prado::using("System.Wsat.TWsatBaseGenerator"); + +class TWsatARGenerator extends TWsatBaseGenerator +{ + + /** + * Class name prefix + */ + private $_clasPrefix; + + /** + * Class name sufix + */ + private $_classSufix; + + /** + * all table relations array + */ + private $_relations; + + /** + * unquote chars + * @var array + */ + private $uqChars = array('[', ']', '"', '`', "'"); + + function __construct() + { + parent::__construct(); + } + + public function setClasPrefix($_clas_prefix) + { + $this->_clasPrefix = $_clas_prefix; + } + + public function setClassSufix($_clas_sufix) + { + $this->_classSufix = $_clas_sufix; + } + +//----------------------------------------------------------------------------- + // <editor-fold defaultstate="collapsed" desc="Main APIs"> + public function generate($tableName) + { + $tableInfo = $this->_dbMetaData->getTableInfo($tableName); + $this->_commonGenerate($tableName, $tableInfo); + } + + public function generateAll() + { + foreach ($this->getAllTableNames() as $tableName) + { + $tableInfo = $this->_dbMetaData->getTableInfo($tableName); + if (!empty($this->_relations)) + { + // Cancel generation of M-M relationships middle table + if (count($tableInfo->getPrimaryKeys()) === 2 && count($tableInfo->getColumns()) === 2)//M-M relationships + continue; + } + $this->_commonGenerate($tableName, $tableInfo); + } + } + + public function buildRelations() + { + $this->_relations = array(); + foreach ($this->getAllTableNames() as $table_name) + { + $tableInfo = $this->_dbMetaData->getTableInfo($table_name); + $pks = $tableInfo->getPrimaryKeys(); + $fks = $tableInfo->getForeignKeys(); + + if (count($pks) === 2 && count($tableInfo->getColumns()) === 2)//M-M relationships + { + $table_name_mm = $fks[0]["table"]; + $table_name_mm2 = $fks[1]["table"]; + + $this->_relations[$table_name_mm][] = array( + "prop_name" => strtolower($table_name_mm2), + "rel_type" => "self::MANY_TO_MANY", + "ref_class_name" => $this->_getProperClassName($table_name_mm2), + "prop_ref" => $table_name + ); + + $this->_relations[$table_name_mm2][] = array( + "prop_name" => strtolower($table_name_mm), + "rel_type" => "self::MANY_TO_MANY", + "ref_class_name" => $this->_getProperClassName($table_name_mm), + "prop_ref" => $table_name + ); + continue; + } + foreach ($fks as $fk_data)//1-M relationships + { + $owner_table = $fk_data["table"]; + $slave_table = $table_name; + $fk_prop = key($fk_data["keys"]); + + $this->_relations[$owner_table][] = array( + "prop_name" => strtolower($slave_table), + "rel_type" => "self::HAS_MANY", + "ref_class_name" => $this->_getProperClassName($slave_table), + "prop_ref" => $fk_prop + ); + + $this->_relations[$slave_table][] = array( + "prop_name" => strtolower($owner_table), + "rel_type" => "self::BELONGS_TO", + "ref_class_name" => $this->_getProperClassName($owner_table), + "prop_ref" => $fk_prop + ); + } + } + } + +// </editor-fold> +//----------------------------------------------------------------------------- + // <editor-fold defaultstate="collapsed" desc="Common Methods"> + + private function _commonGenerate($tableName, $tableInfo) + { + if (count($tableInfo->getColumns()) === 0) + throw new Exception("Unable to find table or view $tableName in " . $this->_dbMetaData->getDbConnection()->getConnectionString() . "."); + else + { + $properties = array(); + foreach ($tableInfo->getColumns() as $field => $metadata) + $properties[] = $this->generateProperty($field, $metadata); + $toString = $this->_buildSmartToString($tableInfo); + } + + $clasName = $this->_getProperClassName($tableName); + $class = $this->generateClass($properties, $tableName, $clasName, $toString); + $output = $this->_opFile . DIRECTORY_SEPARATOR . $clasName . ".php"; + file_put_contents($output, $class); + } + + private function _getProperClassName($tableName) + { + $table_name_words = str_replace("_", " ", strtolower($tableName)); + $final_conversion = str_replace(" ", "", ucwords($table_name_words)); + return $this->_clasPrefix . $final_conversion . $this->_classSufix; + } + +//----------------------------------------------------------------------------- + + protected function generateProperty($field, $metadata) + { + $prop = ''; + $name = '$' . $field; + + /* TODO use in version 2.0 */ + // $type = $column->getPHPType(); + + $prop .= "\tpublic $name;"; + return $prop; + } + + private function _renderRelations($tablename) + { + if (!isset($this->_relations[$tablename])) + return ""; + + $code = "\tpublic static \$RELATIONS = array ("; + foreach ($this->_relations[$tablename] as $rel_data) + $code .= "\n\t\t'" . $rel_data["prop_name"] . "' => array(" . $rel_data["rel_type"] . ", '" . $rel_data["ref_class_name"] . "', '" . $rel_data["prop_ref"] . "'),"; + + $code = substr($code, 0, -1); + $code .= "\n\t);"; + return $code; + } + + private function _buildSmartToString($tableInfo) + { + $code = "\tpublic function __toString() {"; + $property = "throw new THttpException(500, 'Not implemented yet.');"; + try + { + foreach ($tableInfo->getColumns() as $column) + { + if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) + $property = str_replace($this->uqChars, "", $column->ColumnName); + elseif ($column->PdoType == PDO::PARAM_STR && $column->DBType != "date") + { + $property = str_replace($this->uqChars, "", $column->ColumnName); + break; + } + } + } catch (Exception $ex) + { + Prado::trace($ex->getMessage()); + } + $code .= "\n\t\treturn \$this->$property;"; + $code .= "\n\t}"; + return $code; + } + + protected function generateClass($properties, $tablename, $classname, $toString) + { + $props = implode("\n", $properties); + $relations = $this->_renderRelations($tablename); + $date = date('Y-m-d h:i:s'); + $env_user = getenv("username"); + return <<<EOD +<?php +/** + * Auto generated by PRADO - WSAT on $date. + * @author $env_user + */ +class $classname extends TActiveRecord +{ + const TABLE='$tablename'; + +$props + + public static function finder(\$className=__CLASS__) { + return parent::finder(\$className); + } + +$relations + +$toString +} +EOD; + } + +// </editor-fold> +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/TWsatBaseGenerator.php b/lib/prado/framework/Wsat/TWsatBaseGenerator.php new file mode 100644 index 0000000..a87ea37 --- /dev/null +++ b/lib/prado/framework/Wsat/TWsatBaseGenerator.php @@ -0,0 +1,82 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package System.Wsat + */ +Prado::using('System.Data.Common.TDbMetaData'); + +class TWsatBaseGenerator +{ + + /** + * @return TDbMetaData for retrieving metadata information, such as + * table and columns information, from a database connection. + */ + protected $_dbMetaData; + + /** + * Output folder where AR classes will be saved. + */ + protected $_opFile; + + function __construct() + { + if (!class_exists("TActiveRecordManager", false)) + throw new Exception("You need to enable the ActiveRecord module in your application configuration file."); + $ar_manager = TActiveRecordManager::getInstance(); + $_conn = $ar_manager->getDbConnection(); + $_conn->Active = true; + $this->_dbMetaData = TDbMetaData::getInstance($_conn); + } + + public function setOpFile($op_file_namespace) + { + $op_file = Prado::getPathOfNamespace($op_file_namespace); + if (empty($op_file)) + throw new Exception("You need to fix your output folder namespace."); + if (!is_dir($op_file)) + mkdir($op_file, 0777, true); + $this->_opFile = $op_file; + } + + public function renderAllTablesInformation() + { + foreach ($this->getAllTableNames() as $table_name) + { + echo $table_name . "<br>"; + $tableInfo = $this->_dbMetaData->getTableInfo($table_name); + echo "Table info:" . "<br>"; + echo "<pre>"; + print_r($tableInfo); + echo "</pre>"; + } + } + + public function getAllTableNames() + { + $tableNames = $this->_dbMetaData->findTableNames(); + $index = array_search('pradocache', $tableNames); + if ($index) + array_splice($tableNames, $index, 1); + return $tableNames; + } + + public static function pr($data) + { + echo "<pre>"; + print_r($data); + echo "</pre>"; + } + + protected function eq($data) + { + return '"' . $data . '"'; + } + +} diff --git a/lib/prado/framework/Wsat/TWsatScaffoldingGenerator.php b/lib/prado/framework/Wsat/TWsatScaffoldingGenerator.php new file mode 100644 index 0000000..1490f23 --- /dev/null +++ b/lib/prado/framework/Wsat/TWsatScaffoldingGenerator.php @@ -0,0 +1,162 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 4.0 + * @package System.Wsat + */ +Prado::using("System.Wsat.TWsatBaseGenerator"); + +class TWsatScaffoldingGenerator extends TWsatBaseGenerator +{ + + /** + * Const View Types for generation + */ + const LIST_TYPE = 0; + const ADD_TYPE = 1; + const SHOW_TYPE = 2; + + /** + * Bootstrap option + */ + private $_bootstrap; + + function __construct() + { + parent::__construct(); + } + + /** + * Generates CRUD Operations for a single DB table + * @param type $tableName + */ + public function generateCRUD($tableName) + { + $this->generate($tableName, self::ADD_TYPE); + $this->generate($tableName, self::LIST_TYPE); + $this->generate($tableName, self::SHOW_TYPE); + } + + //--------------------------------------------------------------------- + // <editor-fold defaultstate="collapsed" desc="Page Generation"> + public function generate($tableName, $viewType) + { + switch ($viewType) + { + default: + case self::LIST_TYPE: + $unitName = "list" . ucfirst($tableName); + break; + + case self::ADD_TYPE: + $unitName = "add" . ucfirst($tableName); + break; + + case self::SHOW_TYPE: + $unitName = "show" . ucfirst($tableName); + break; + } + + $class = $this->generateClass($unitName); + $outputClass = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".php"; + file_put_contents($outputClass, $class); + + $outputPage = $this->_opFile . DIRECTORY_SEPARATOR . $unitName . ".page"; + $page = $this->generatePage($tableName, $viewType); + file_put_contents($outputPage, $page); + } + + private function generatePage($tableName, $type, $tContentId = "Content") + { + $pageContent = $this->getPageContent($tableName, $type); + return <<<EOD +<com:TContent ID="$tContentId"> + + $pageContent + +</com:TContent> +EOD; + } + + private function getPageContent($tableName, $type) + { + $code = ""; + $tableInfo = $this->_dbMetaData->getTableInfo($tableName); + switch ($type) + { + case self::LIST_TYPE: + break; + case self::ADD_TYPE: + foreach ($tableInfo->getColumns() as $colField => $colMetadata) + { + if (!$colMetadata->IsPrimaryKey && !$colMetadata->IsForeignKey) + { + $code .= $this->generateControl($colMetadata); + $code .= $this->generateValidators($colMetadata); + $code .= "\n"; + } + } + foreach ($tableInfo->getForeignKeys() as $colField => $colMetadata) + { + $colField = $this->eq($colMetadata["table"]); + $code .= "\t<com:TTextBox ID=$colField />\n"; + $code .= "\n"; + // TWsatBaseGenerator::pr($tableInfo); + } + $code .= "\t<com:TButton Text=\"Accept\" />\n"; + + case self::SHOW_TYPE: + break; + } + return $code; + } + + private function generateControl($colMetadata) + { + $controlType = "TTextBox"; + switch ($colMetadata->DbType) + { + + } + $controlId = $colMetadata->ColumnId; + return "\t<com:$controlType ID=\"$controlId\" />\n"; + } + + private function generateValidators($colMetadata) + { + $controlId = $colMetadata->ColumnId; + $code = ""; + if (!$colMetadata->AllowNull) + { + $code .= "\t<com:TRequiredFieldValidator ControlToValidate=$controlId ValidationGroup=\"addGroup\" Text=\"Field $controlId is required.\" Display=\"Dynamic\" />\n"; + } + return $code; + } + +// </editor-fold> + //--------------------------------------------------------------------- + // <editor-fold defaultstate="collapsed" desc="Code Behind Generation"> + private function generateClass($classname) + { + $date = date('Y-m-d h:i:s'); + $env_user = getenv("username"); + return <<<EOD +<?php +/** + * Auto generated by PRADO - WSAT on $date. + * @author $env_user + */ +class $classname extends TPage +{ + +} +EOD; + } + +// </editor-fold> +} diff --git a/lib/prado/framework/Wsat/TWsatService.php b/lib/prado/framework/Wsat/TWsatService.php new file mode 100644 index 0000000..0c33a49 --- /dev/null +++ b/lib/prado/framework/Wsat/TWsatService.php @@ -0,0 +1,81 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package System.Wsat + */ + +/** + * TWsatService class + * + * Wsat is inspired in both Asp.Net - Web Site Administration Tool(WSAT) and Yii's Gii. + * Wsat enables you to generate code saving your time in too many tedious tasks in a GUI fashion. + * + * Current options: + * 1- Generate one or all Active Record Classes from your DataBase. + * 1.1- Automatically generate all relations between the AR Classes (new). + * 1.2- Automatically generate the __toString() magic method in a smart way (new). + * + * To use TWsatService, configure it in the application configuration file like following: + * <code> + * <services> + * ... + * <service id="wsat" class="System.Wsat.TWsatService" Password="my_secret_password" /> + * </services> + * </code> + * ...and then you need to go to http://localhost/yoursite/index.php?wsat=TWsatLogin + * and generate code and configure your site. + * + * Warning: You should only use Wsat in development mode. + */ +class TWsatService extends TPageService +{ + + private $_pass = ''; + + public function init($config) + { + if ($this->getApplication()->getMode() === TApplicationMode::Performance || $this->getApplication()->getMode() === TApplicationMode::Normal) + throw new TInvalidOperationException("You should not use Prado WSAT in any of the production modes."); + + if (empty($this->_pass)) + throw new TConfigurationException("You need to specify the Password attribute."); + + $this->setDefaultPage("TWsatHome"); + $this->_startThemeManager(); + parent::init($config); + } + + public function getBasePath() + { + $basePath = Prado::getPathOfNamespace("System.Wsat.pages"); + return realpath($basePath); + } + + private function _startThemeManager() + { + $themeManager = new TThemeManager; + $themeManager->BasePath = "System.Wsat.themes"; + $url = Prado::getApplication()->getAssetManager()->publishFilePath(Prado::getPathOfNamespace('System.Wsat')); + $themeManager->BaseUrl = "$url/themes"; + + $themeManager->init(null); + $this->setThemeManager($themeManager); + } + + public function getPassword() + { + return $this->_pass; + } + + public function setPassword($_pass) + { + $this->_pass = $_pass; + } + +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/TWsatGenerateAR.page b/lib/prado/framework/Wsat/pages/TWsatGenerateAR.page new file mode 100644 index 0000000..53ccc16 --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatGenerateAR.page @@ -0,0 +1,56 @@ +<com:TContent ID="Content"> + <div class="section_title">Active Record Classes Generator</div> + <div class="green_panel" style="text-align: left; font-size: 14px; margin: 15px 5px"> + <label>This tool generates an AR class for the specified database table.</label><br/> + <label>Fields with <b style="color: red">*</b> are required.</label> + <hr/> + <div style="font-size: 12px; font-style: italic"> + <ul> + <li>If you want to generate all AR Classes, keep the "Table Name" field as appears by default.</li> + <li>"Output Folder" field refers to the directory that the new AR class file should be generated under... where Application refers to the protected folder of your project. You can let this default field value and PRADO will create the proper folders for you.</li> + </ul> + </div> + </div> + + <div style="font-size: 14px"> + <div class="form_row"> + <com:TLabel Text="Table Name:" ForControl="table_name" style="margin-right: 24px" /> + <com:TTextBox ID="table_name" Text="*" CssClass="in_text" /> + <label style="color: red">*</label> + <com:TRequiredFieldValidator ControlToValidate="table_name" Text="Table name cannot be blank." Display="Dynamic" /> + </div> + + <div class="form_row"> + <com:TLabel Text="Output Folder:" ForControl="output_folder" style="margin-right: 8px"/> + <com:TTextBox ID="output_folder" Text="Application.App_Data.AR_Classes" CssClass="in_text" /> + <label style="color: red">*</label> + <com:TRequiredFieldValidator ControlToValidate="output_folder" Text="Output folder cannot be blank." Display="Dynamic" /> + </div> + + <div class="form_row"> + <com:TLabel Text="Class Prefix:" ForControl="class_prefix" style="margin-right: 25px"/> + <com:TTextBox ID="class_prefix" Text="AR_" CssClass="in_text" /> + </div> + + <div class="form_row"> + <com:TLabel Text="Class Suffix:" ForControl="class_suffix" style="margin-right: 27px"/> + <com:TTextBox ID="class_suffix" CssClass="in_text" /> + </div> + + <div class="form_row"> + <com:TLabel Text="Build Relations:" ForControl="build_rel"/> + <com:TCheckBox ID="build_rel" Checked="true" /> + </div> + + <com:TPanel ID="feedback_panel" Visible="false" style="width: 400px"> + <com:TLabel ID="generation_msg" /> + </com:TPanel> + + <br/> + <div style="text-align: center; width: 400px"> + <com:TButton Text="Preview" OnClick="preview" Visible="false" /> + <com:TButton Text="Generate" OnClick="generate" /> + </div> + </div> + +</com:TContent> diff --git a/lib/prado/framework/Wsat/pages/TWsatGenerateAR.php b/lib/prado/framework/Wsat/pages/TWsatGenerateAR.php new file mode 100644 index 0000000..1677a8e --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatGenerateAR.php @@ -0,0 +1,57 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package Wsat.pages + */ +Prado::using("System.Wsat.TWsatARGenerator"); + +class TWsatGenerateAR extends TPage +{ + + public function generate($sender) + { + if ($this->IsValid) + { + $tableName = $this->table_name->Text; + $outputFolderNs = $this->output_folder->Text; + $classPrefix = $this->class_prefix->Text; + $classSuffix = $this->class_suffix->Text; + + try + { + $ar_generator = new TWsatARGenerator(); + $ar_generator->setOpFile($outputFolderNs); + $ar_generator->setClasPrefix($classPrefix); + $ar_generator->setClassSufix($classSuffix); + + if ($this->build_rel->Checked) + $ar_generator->buildRelations(); + + if ($tableName != "*") + $ar_generator->generate($tableName); + else + $ar_generator->generateAll(); + + $this->feedback_panel->CssClass = "green_panel"; + $this->generation_msg->Text = "The code has been generated successfully."; + } catch (Exception $ex) + { + $this->feedback_panel->CssClass = "red_panel"; + $this->generation_msg->Text = $ex->getMessage(); + } + $this->feedback_panel->Visible = true; + } + } + + public function preview($sender) + { + throw new THttpException(500, "Not implemented yet."); + } + +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/TWsatHome.page b/lib/prado/framework/Wsat/pages/TWsatHome.page new file mode 100644 index 0000000..3083a39 --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatHome.page @@ -0,0 +1,27 @@ +<com:TContent ID="Content"> + <label style="font-size: 18px; font-weight: bold">Welcome to the Web Site Administration Tool</label> + + <div style="margin-top: 25px"><b>Application Dir:</b> <%= Prado::getPathOfNamespace('Application') %></div> + + <br/> + <table> + <tr style="background-color: #cccccc"> + <td style="padding: 5px; width: 100px"> + <com:THyperLink NavigateUrl="<%= $this->Service->constructUrl('TWsatGenerateAR') %>" Text="AR Classes" /> + </td> + <td style="padding: 5px"> + Enables you to generate all Active Record Classes with relations included. + </td> + </tr> + <!--- + <tr style="background-color: #cccccc"> + <td style="padding: 5px; width: 100px"> + <com:THyperLink NavigateUrl="<%= $this->Service->constructUrl('TWsatScaffolding') %>" Text="Scaffolding" /> + </td> + <td style="padding: 5px"> + Enables you to generate a completed CRUD based in DB tables. It allow to choose bootstrap for the view generation. + </td> + </tr> + ---> + </table> +</com:TContent> diff --git a/lib/prado/framework/Wsat/pages/TWsatHome.php b/lib/prado/framework/Wsat/pages/TWsatHome.php new file mode 100644 index 0000000..6e1b72d --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatHome.php @@ -0,0 +1,17 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package Wsat.pages + */ +Prado::using("System.Wsat.TWsatARGenerator"); + +class TWsatHome extends TPage +{ + +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/TWsatLogin.page b/lib/prado/framework/Wsat/pages/TWsatLogin.page new file mode 100644 index 0000000..6b9d845 --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatLogin.page @@ -0,0 +1,44 @@ +<%@ MasterClass="" %> + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> + <com:THead Title="PRADO - WSAT"> + <com:TMetaTag HttpEquiv="Content-Type" Content="text/html; charset=utf-8" /> + <com:TMetaTag HttpEquiv="Content-Language" Content="en" /> + </com:THead> + + <body> + <com:TForm> + + <div id="header"> + <a href="<%= $this->Service->DefaultPageUrl %>"> + <div class="logo"></div> + <div style="float: left; margin-top: 17px">PRADO <br /> Web Site Administration Tool</div> + </a> + <div class="mantisbg"></div> + <div style="clear: both"></div> + </div> + + <div class="mainmenu"> + <div style="float: right"><com:THyperLink NavigateUrl="https://github.com/pradosoft/prado" Text="Prado framework" Target="_blank" /> | </div> + <div style="float: right"><com:THyperLink NavigateUrl="<%= $this->Service->DefaultPageUrl %>" Text="Web App" Target="_blank" /> | </div> + <div style="clear: both"></div> + </div> + + <div class="login_form"> + <com:TLabel Text="Please enter your password:" ForControl="password"/><br/> + <com:TTextBox ID="password" TextMode="Password" style="margin: 5px" /><br/> + <com:TRequiredFieldValidator ControlToValidate="password" ValidationGroup="loginGroup" Text="Password cannot be blank." Display="Dynamic" /><br/> + <com:TCustomValidator ControlToValidate="password" ValidationGroup="loginGroup" OnServerValidate="validatePassword" Text="Incorrect password." Display="Dynamic" /> + + <div><com:TButton Text="Enter" ValidationGroup="loginGroup" OnClick="login" /></div> + </div> + + <div id="footer"> + Copyright © 2005-<%= date('Y') %> <a href="https://github.com/pradosoft">The PRADO Group</a>. + <br/><br/> + <%= Prado::poweredByPrado() %> + </div> + </com:TForm> + </body> +</html> diff --git a/lib/prado/framework/Wsat/pages/TWsatLogin.php b/lib/prado/framework/Wsat/pages/TWsatLogin.php new file mode 100644 index 0000000..cfd4d56 --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatLogin.php @@ -0,0 +1,32 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package Wsat.pages + */ +class TWsatLogin extends TPage +{ + + public function login() + { + if ($this->IsValid) + { + $this->Session["wsat_password"] = $this->getService()->getPassword(); + $url = $this->Service->constructUrl('TWsatHome'); + $this->Response->redirect($url); + } + } + + public function validatePassword($sender, $param) + { + $config_pass = $this->Service->Password; + $user_pass = $this->password->Text; + $param->IsValid = $user_pass === $config_pass; + } + +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/TWsatScaffolding.page b/lib/prado/framework/Wsat/pages/TWsatScaffolding.page new file mode 100644 index 0000000..f3e53df --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatScaffolding.page @@ -0,0 +1,23 @@ +<com:TContent ID="Content"> + <div class="section_title">Scaffolding Generator</div> + + <div> + <com:TPanel ID="tableNames" GroupingText="Select tables to generate CRUD for:" Width="400px"/> + </div> + + <div class="form_row"> + <com:TLabel Text="Output Folder:" ForControl="output_folder" style="margin-right: 8px"/> + <com:TTextBox ID="output_folder" Text="Application.pages" CssClass="in_text" /> + <label style="color: red">*</label> + <com:TRequiredFieldValidator ControlToValidate="output_folder" Text="Output folder cannot be blank." Display="Dynamic" /> + </div> + + <com:TPanel ID="feedback_panel" Visible="false" style="width: 400px"> + <com:TLabel ID="generation_msg" /> + </com:TPanel> + + <div style="text-align: center; width: 400px"> + <com:TButton Text="Preview" OnClick="preview" Visible="false" /> + <com:TButton Text="Generate" OnClick="generate" /> + </div> +</com:TContent> diff --git a/lib/prado/framework/Wsat/pages/TWsatScaffolding.php b/lib/prado/framework/Wsat/pages/TWsatScaffolding.php new file mode 100644 index 0000000..b480174 --- /dev/null +++ b/lib/prado/framework/Wsat/pages/TWsatScaffolding.php @@ -0,0 +1,72 @@ +<?php + +/** + * @author Daniel Sampedro Bello <darthdaniel85@gmail.com> + * @link https://github.com/pradosoft/prado + * @copyright Copyright © 2005-2015 The PRADO Group + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT + * @version $Id$ + * @since 3.3 + * @package Wsat.pages + */ +Prado::using("System.Wsat.TWsatScaffoldingGenerator"); + +class TWsatScaffolding extends TPage +{ + + public function onInit($param) + { + parent::onInit($param); + $this->startVisual(); + } + + private function startVisual() + { + $scf_generator = new TWsatScaffoldingGenerator(); + foreach ($scf_generator->getAllTableNames() as $tableName) + { + $dynChb = new TCheckBox(); + $dynChb->ID = "cb_$tableName"; + $dynChb->Text = ucfirst($tableName); + $dynChb->Checked = true; + $this->registerObject("cb_$tableName", $dynChb); + $this->tableNames->getControls()->add($dynChb); + $this->tableNames->getControls()->add("</br>"); + } + } + + /** + * Generate Scaffolding code for selected tables + * @param type $sender + */ + public function generate($sender) + { + if ($this->IsValid) + { + try + { + $scf_generator = new TWsatScaffoldingGenerator(); + $scf_generator->setOpFile($this->output_folder->Text); + foreach ($scf_generator->getAllTableNames() as $tableName) + { + $id = "cb_$tableName"; + $obj = $this->tableNames->findControl($id); + if($obj!==null && $obj->Checked) + { + $scf_generator->generateCRUD($tableName); + } + } + + $this->feedback_panel->CssClass = "green_panel"; + $this->generation_msg->Text = "The code has been generated successfully."; + } catch (Exception $ex) + { + $this->feedback_panel->CssClass = "red_panel"; + $this->generation_msg->Text = $ex->getMessage(); + } + $this->feedback_panel->Visible = true; + } + + // $scf_generator->renderAllTablesInformation(); + } +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/config.xml b/lib/prado/framework/Wsat/pages/config.xml new file mode 100644 index 0000000..727e8ea --- /dev/null +++ b/lib/prado/framework/Wsat/pages/config.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<configuration> + <modules> + <module id="session" class="THttpSession" CookieMode="Allow" UseCustomStorage="false" + AutoStart="true" GCProbability="1" UseTransparentSessionID="true" TimeOut="3600" /> + </modules> + <pages Theme="PradoSoft" MasterClass="System.Wsat.pages.layout.TWsatLayout" /> +</configuration>
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/layout/TWsatLayout.php b/lib/prado/framework/Wsat/pages/layout/TWsatLayout.php new file mode 100644 index 0000000..67caa77 --- /dev/null +++ b/lib/prado/framework/Wsat/pages/layout/TWsatLayout.php @@ -0,0 +1,36 @@ +<?php + +/** + * Description of MainLayout + * + * @author daniels + */ +class TWsatLayout extends TTemplateControl +{ + + public function onLoad($param) + { + parent::onLoad($param); + $this->validateSecurity(); + } + + private function validateSecurity() + { + if ($this->Session["wsat_password"] !== $this->getService()->getPassword()) + { + if (!$this->getPage() instanceof TWsatLogin) + { + $url = $this->Service->constructUrl('TWsatLogin'); + $this->Response->redirect($url); + } + } + } + + public function logout() + { + $this->Session["wsat_password"] = ""; + $url = $this->Service->constructUrl('TWsatLogin'); + $this->Response->redirect($url); + } + +}
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/pages/layout/TWsatLayout.tpl b/lib/prado/framework/Wsat/pages/layout/TWsatLayout.tpl new file mode 100644 index 0000000..36ec5ba --- /dev/null +++ b/lib/prado/framework/Wsat/pages/layout/TWsatLayout.tpl @@ -0,0 +1,54 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> + <com:THead Title="PRADO - WSAT"> + <com:TMetaTag HttpEquiv="Content-Type" Content="text/html; charset=utf-8" /> + <com:TMetaTag HttpEquiv="Content-Language" Content="en" /> + </com:THead> + + <body> + <com:TForm> + + <div id="header"> + <a href="<%= $this->Service->DefaultPageUrl %>"> + <div class="logo"></div> + <div style="float: left; margin-top: 17px">PRADO <br /> Web Site Administration Tool</div> + </a> + <div class="mantisbg"></div> + <div style="clear: both"></div> + </div> + + <div class="mainmenu"> + <div style="float: right"><com:TLinkButton Text="Logout" OnClick="logout" /></div> + <div style="float: right"><com:THyperLink NavigateUrl="https://github.com/pradosoft/prado" Text="Prado framework" Target="_blank" /> | </div> + <div style="float: right"><com:THyperLink NavigateUrl="<%= $this->Service->DefaultPageUrl %>" Text="Web App" Target="_blank" /> | </div> + <div style="clear: both"></div> + </div> + + <div id="central_div"> + <div id="toc"> + <div class="topic"> + <div>Code Generation</div> + <ul> + <li><com:THyperLink NavigateUrl="<%= $this->Service->constructUrl('TWsatGenerateAR') %>" Text="AR Classes" /></li> + <!--- + <li><com:THyperLink NavigateUrl="<%= $this->Service->constructUrl('TWsatScaffolding') %>" Text="Scaffolding" /></li> + ---> + </ul> + </div> + </div> + + <div id="content"> + <com:TContentPlaceHolder ID="Content" /> + </div> + + <div style="clear: both"></div> + </div> + + <div id="footer"> + Copyright © 2005-<%= date('Y') %> <a href="https://github.com/pradosoft">The PRADO Group</a>. + <br/><br/> + <%= Prado::poweredByPrado() %> + </div> + </com:TForm> + </body> +</html>
\ No newline at end of file diff --git a/lib/prado/framework/Wsat/themes/.htaccess b/lib/prado/framework/Wsat/themes/.htaccess new file mode 100644 index 0000000..f7661d0 --- /dev/null +++ b/lib/prado/framework/Wsat/themes/.htaccess @@ -0,0 +1 @@ +allow from all diff --git a/lib/prado/framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif b/lib/prado/framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif Binary files differnew file mode 100644 index 0000000..1b508cd --- /dev/null +++ b/lib/prado/framework/Wsat/themes/PradoSoft/imgs/arrowdown.gif diff --git a/lib/prado/framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg b/lib/prado/framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg Binary files differnew file mode 100644 index 0000000..ee06998 --- /dev/null +++ b/lib/prado/framework/Wsat/themes/PradoSoft/imgs/mantisbg.jpg diff --git a/lib/prado/framework/Wsat/themes/PradoSoft/imgs/pradologo.gif b/lib/prado/framework/Wsat/themes/PradoSoft/imgs/pradologo.gif Binary files differnew file mode 100644 index 0000000..20ecf81 --- /dev/null +++ b/lib/prado/framework/Wsat/themes/PradoSoft/imgs/pradologo.gif diff --git a/lib/prado/framework/Wsat/themes/PradoSoft/main.css b/lib/prado/framework/Wsat/themes/PradoSoft/main.css new file mode 100644 index 0000000..d525f96 --- /dev/null +++ b/lib/prado/framework/Wsat/themes/PradoSoft/main.css @@ -0,0 +1,158 @@ +html, body{ + margin: 0px; + padding: 0px; + font-family: 'Lucida Grande', Verdana, Geneva, Lucida, Helvetica, Arial, sans-serif; + font-weight: normal; +} + +#header { + font-size:25px; + font-weight:bold; + color: #666; +} + +.logo{ + width: 204px; + height:100px; + background-image: url('imgs/pradologo.gif'); + background-repeat: no-repeat; + float: left; +} + +.mantisbg{ + width: 221px; + height: 100px; + background-image: url('imgs/mantisbg.jpg'); + background-repeat: no-repeat; + float: right; +} + +.mainmenu { + padding:10px; + padding-right:10px; + background:#EDEDED; + border-bottom: 1px solid #A6A6A6; + border-top: 1px solid #DCDCDC; + color:white; + text-align:right; + font-size: 10pt; +} + +.mainmenu a { + color:#737373; + text-decoration:none; +} + +.mainmenu a:hover { + color: #FF0000; +} + +#toc { + background-color: #F3F3F3; + width:220px; + padding:0px 10px 0px 10px; + float: left; +} + +#content { + padding: 1em 1em 1em 1em; + line-height: 135%; + float: left; + width: 700px; +} + +.topic { + font-size: 9pt; + padding: 0px 0px 0px 0px; +} + +.topic div { + background-image: url('imgs/arrowdown.gif'); + background-repeat: no-repeat; + background-position: left center; + margin: 0px; + font-size: 8pt; + font-weight:bold; + color:#2A480A; + padding: 5px; + padding-left: 15px; + border-top: 1px solid #fff; + border-bottom: 1px solid #E2E2E2; +} + +.topic ul +{ + margin: 0px; + padding: 0px; +} + +.topic ul li +{ + list-style: none; + margin: 0px; + padding: 5px; + padding-left: 15px; + border-bottom: 1px dotted #D8D8D8; +} + +.topic a { + color:#4F811A; + font-size: 8pt; + text-decoration: none; +} + +.topic a:hover { + color:#2A480A; +} + +/* form styles */ +.form_row{ + margin: 10px; +} + +.in_text{ + width: 250px; +} + +.login_form{ + text-align: center; + margin: 30px auto; + border: 1px solid red; + border-radius: 5px; + padding: 10px; + width: 250px; + font-size: 11px; +} + +.green_panel{ + background-color: #C5FBBD; + border: 1px solid #76C376; + padding: 10px; + margin: 10px 0; + border-radius: 5px; + text-align: center; +} + +.red_panel{ + background-color: #ff6666; + border: 1px solid red; + padding: 10px; + margin: 10px 0; + border-radius: 5px; + text-align: center; +} + +#footer { + clear:both; + color: gray; + font-size:8pt; + text-align:center; + margin-top:25px; + padding:10px; +} + +.section_title { + margin: 10px; + font-size: 16px; + font-weight: bold +}
\ No newline at end of file |