コード例 #1
0
ファイル: Columnator.php プロジェクト: raxisau/JackBooted
 /**
  * Create a Columnator Object.
  * @param array $props This is the properties that the Columnator will use to display.
  * <pre>
  * $props = array ( 'attribs'          => 'array ( 'style' => 'display:none ), // Optional,
  *                                        // Attributes that will be stamped on the div that is generated
  *                                        // if not supplied will be empty array.
  *                                        // Need to supply if the primary key is not simple column name
  *                  'suffix'           => 'V', // Optional, suffix for the action variable for Columnator
  *                                        // useful when there is a numbner on the screen
  *                                        // if not supplied one will be generated based on the number of
  *                                        // Columnator that are generated
  *                  'request_vars'     => 'CEMID', // Optional, regexpression or individual name of any request
  *                                        //  vars that are to be copied to the response vars (chained vars)
  *                  'init_column'      => 'fldDate', // Optional, Initial Coloumn to be sorted
  *                  'init_order'       => 'DESC', // Optional, initial direction
  *                );
  * </pre>
  */
 public function __construct($props = [])
 {
     parent::__construct();
     $this->attribs = isset($props['attribs']) ? $props['attribs'] : [];
     $suffix = isset($props['suffix']) ? $props['suffix'] : Invocation::next();
     $this->navVar = self::navVar($suffix);
     $initPattern = isset($props['request_vars']) ? $props['request_vars'] : '';
     $this->respVars = new Response($initPattern);
     $initialVars = self::$columnation;
     $initialVars[self::SORT_COL] = isset($props['init_column']) ? $props['init_column'] : '';
     $initialVars[self::SORT_ORDER] = isset($props['init_order']) ? $props['init_order'] : '';
     // ensyre that they have been set
     $requestColumnVars = Request::get($this->navVar, []);
     foreach ($initialVars as $key => $val) {
         $this->set($key, isset($requestColumnVars[$key]) ? $requestColumnVars[$key] : $val);
     }
     // Get the current settings
     $this->sortColumn = $this->formVars[self::SORT_COL];
     $this->sortOrder = $this->formVars[self::SORT_ORDER];
     if (!isset($this->sortOrder) || $this->sortOrder == false || !in_array($this->sortOrder, ['ASC', 'DESC'])) {
         $this->sortOrder = 'ASC';
     }
     $this->styles[self::COL_LINK_CLASS] = 'jb-collink';
     $this->styles[self::COL_BUTTON_CLASS] = 'jb-colbutton';
 }
コード例 #2
0
ファイル: MenuUtils.php プロジェクト: raxisau/JackBooted
    public static function display($menuClasses = null)
    {
        $id = 'MenuUtils_display' . Invocation::next();
        $jsLibraries = JS::libraryWithDependancies(JS::JQUERY_UI);
        $activeMenu = Request::get(self::ACTIVE_MENU, 0);
        $js = <<<JS
            \$().ready ( function () {
                \$( '#{$id}' ).show()
                           .accordion({
                    collapsible: true,
                    active: {$activeMenu}
                });
            });
JS;
        $html = '';
        $html .= Tag::div(['id' => $id, 'style' => 'font-size: 0.8em; width:250px; text-align:left; display:none;']);
        foreach (self::getMenuItems($menuClasses) as $header => $menuList) {
            $html .= Tag::hTag('h3') . Tag::hRef('#', $header) . Tag::_hTag('h3') . Tag::div() . Tag::ul();
            foreach ($menuList as $row) {
                $html .= Tag::li();
                if (isset($row['slug'])) {
                    $html .= Tag::hRef(Cfg::siteUrl() . '/menu.php?S=' . $row['slug'], $row['name'], $row['attribs']);
                } else {
                    $html .= Tag::hRef($row['url'], $row['name'], $row['attribs']);
                }
                $html .= Tag::_li();
            }
            $html .= Tag::_ul() . Tag::_div();
        }
        $html .= Tag::_div();
        return $jsLibraries . JS::javaScript($js) . $html;
    }
コード例 #3
0
ファイル: Paginator.php プロジェクト: raxisau/JackBooted
 /**
  * Create a Pagination Object.
  * @param array $props This is the properties that the Paginator will use to display.
  * <pre>
  * $props = array ( 'attribs'          => 'array ( 'style' => 'display:none ), // Optional,
  *                                        // Attributes that will be stamped on the div that is generated
  *                                        // if not supplied will be empty array.
  *                                        // Need to supply if the primary key is not simple column name
  *                  'suffix'           => 'V', // Optional, suffix for the action variable for paginator
  *                                        // useful when there is a numbner on the screen
  *                                        // if not supplied one will be generated based on the number of
  *                                        // paginators that are generated
  *                  'request_vars'     => 'CEMID', // Optional, regexpression or individual name of any request
  *                                        //  vars that are to be copied to the response vars (chained vars)
  *                  'display_pagesize' => true, // Optional defaults to true. If false the page sizes will not
  *                                        // be displayed
  *                  'rows'             => 100,  // Optional. Number of rows that the Paginator has to deal with
  *                                        // Based on this number and the number of rows per page, the number of
  *                                        // pages are calculated
  *                  'def_num_rows'     => 15,  // Optional. Number of rows default on this pagination
  *                );
  * </pre>
  */
 public function __construct($props = [])
 {
     parent::__construct();
     $this->attribs = isset($props['attribs']) ? $props['attribs'] : [];
     $suffix = isset($props['suffix']) ? $props['suffix'] : Invocation::next();
     $this->navVar = self::navVar($suffix);
     $initPattern = isset($props['request_vars']) ? $props['request_vars'] : '';
     $this->respVars = new Response($initPattern);
     $this->dispPageSize = isset($props['display_pagesize']) ? $props['display_pagesize'] : true;
     $defPagination = array_merge(self::$pagination);
     if (isset($props['def_num_rows'])) {
         $defPagination[self::ROWS_PER_PAGE] = $props['def_num_rows'];
     }
     if (!in_array($defPagination[self::ROWS_PER_PAGE], self::$itemsPerPageList)) {
         self::$itemsPerPageList[] = $defPagination[self::ROWS_PER_PAGE];
         sort(self::$itemsPerPageList);
     }
     // ensure that they have been set
     $requestPageVars = Request::get($this->navVar, []);
     foreach ($defPagination as $key => $val) {
         $this->set($key, isset($requestPageVars[$key]) ? $requestPageVars[$key] : $val);
     }
     if (isset($props['rows'])) {
         $this->setRows((int) $props['rows']);
     }
     $this->styles[self::PAGE_LINK_CLASS] = 'jb-pagelink';
     $this->styles[self::PAGE_BUTTON_CLASS] = 'jb-pagebuton';
     if ($this->getStart() > 0 && $this->getRows() < $this->getPageSize()) {
         $this->setStart(0);
     }
 }
コード例 #4
0
ファイル: CSV.php プロジェクト: raxisau/JackBooted
 public static function output($table, $name = '')
 {
     if (!is_object($table) && !is_array($table)) {
         exit;
     }
     if ($name == '') {
         $name = 'output' . Invocation::next();
     }
     if (!preg_match('/^.*\\.csv$/i', $name)) {
         $name .= '.csv';
     }
     header('Content-type: application/octet-stream');
     header('Content-Disposition: attachment; filename="' . $name . '"');
     $firstRow = true;
     if ($table instanceof DBTable || is_array($table)) {
         foreach ($table as $row) {
             // Output the headers
             if ($firstRow) {
                 echo join(',', array_keys($row)), "\n";
             }
             $firstRow = false;
             // Output the data
             $firstValue = true;
             foreach ($row as $key => $val) {
                 if (!$firstValue) {
                     echo ',';
                 }
                 $firstValue = false;
                 echo '"' . addcslashes($val, '"') . '"';
             }
             echo "\n";
         }
     } else {
         if ($table instanceof \PDOStatement) {
             while ($row = $table->fetch(DB::FETCH_ASSOC)) {
                 if ($firstRow) {
                     echo join(',', array_keys($row)), "\n";
                 }
                 $firstRow = false;
                 // Output the data
                 $firstValue = true;
                 foreach ($row as $key => $val) {
                     if (!$firstValue) {
                         echo ',';
                     }
                     $firstValue = false;
                     echo '"' . addcslashes($val, '"') . '"';
                 }
                 echo "\n";
             }
         }
     }
     exit;
 }
コード例 #5
0
ファイル: XLS.php プロジェクト: raxisau/JackBooted
 public static function output($table, $name = '')
 {
     error_reporting(0);
     if (!is_object($table) && !is_array($table)) {
         exit;
     }
     if ($name == '') {
         $name = 'output' . Invocation::next();
     }
     if (!preg_match('/^.*\\.xls$/i', $name)) {
         $name .= '.xls';
     }
     $fileName = PHPExt::getTempDir() . '/' . $name;
     $workbook = new Spreadsheet_Excel_Writer($fileName);
     $worksheet =& $workbook->addWorksheet(basename($name));
     $rowIdx = 0;
     if ($table instanceof DBTable || is_array($table)) {
         foreach ($table as $row) {
             if ($rowIdx == 0) {
                 foreach (array_keys($row) as $col => $heading) {
                     $worksheet->write($rowIdx, $col, $heading);
                 }
                 $rowIdx++;
             }
             foreach (array_values($row) as $col => $val) {
                 $worksheet->write($rowIdx, $col, $val);
             }
             $rowIdx++;
         }
     } else {
         if ($table instanceof PDOStatement) {
             while ($row = $table->fetch(DB::FETCH_ASSOC)) {
                 if ($rowIdx == 0) {
                     foreach (array_keys($row) as $col => $heading) {
                         $worksheet->write($rowIdx, $col, $heading);
                     }
                     $rowIdx++;
                 }
                 foreach (array_values($row) as $col => $val) {
                     $worksheet->write($rowIdx, $col, $val);
                 }
                 $rowIdx++;
             }
         }
     }
     $workbook->close();
     $workbook->send($name);
     $fp = fopen($fileName, 'rb');
     fpassthru($fp);
     fclose($fp);
     unlink($fileName);
     exit;
 }
コード例 #6
0
ファイル: DBTable.php プロジェクト: raxisau/JackBooted
 public function __toString()
 {
     $id = 'DBTable_' . Invocation::next();
     $msg = '<table id="' . $id . '">';
     if ($this->getRowCount() == 0) {
         $msg .= '<tr><td>No Rows</td></tr>';
     } else {
         $firstTime = true;
         foreach ($this->table as &$row) {
             if ($firstTime) {
                 $msg .= '  <tr>';
                 foreach ($row as $key => &$value) {
                     $msg .= '<th>' . $key . '</th>';
                 }
                 $msg .= '  </tr>' . "\n";
                 $firstTime = false;
             }
             $msg .= '  <tr>';
             foreach ($row as &$value) {
                 $msg .= '<td>' . $value . '</td>';
             }
             $msg .= '  </tr>' . "\n";
         }
     }
     $msg .= '</table>' . "\n";
     return Widget::styleTable('#' . $id) . $msg;
 }
コード例 #7
0
ファイル: Tag.php プロジェクト: raxisau/JackBooted
 public static function hRefButton($url, $name, $attribs = [])
 {
     if (is_string($attribs)) {
         $attribs = [$attribs];
     }
     if (!isset($attribs['id'])) {
         $attribs['id'] = 'linkButton_' . Invocation::next();
     }
     return Widget::button("#{$attribs['id']}") . self::hRef($url, $name, $attribs);
 }
コード例 #8
0
ファイル: CRUD.php プロジェクト: raxisau/JackBooted
 /**
  * Create the CRUD Object.
  * @param string $tableName The name of the table
  * @param array $extraArgs This is the properties that the CRUD will use to display/populate the database.
  * <pre>
  * $props = array ( 'primaryKey' => 'id', // Optional, if not supplied will be calculated.
  *                                        // Need to supply if the primary key is not simple column name
  *                  'db' => 'mydb',       // Optional, Name of the database. If not supplied defaults to DB::DEF
  *                                        // Database must be set up in the configuration
  *                  'where' => array ( 'pid' => 5 ),
  *                                        // Optional, List of conditions for the rows that we are looking for.
  *                                        // This would be used when looking for foreign key. These values will
  *                                        // be automatically inserted in new rows
  *                  'userCols' => array ( 'Mapping' => array ( $this, 'managePrivilegesCallBack' ) ),
  *                                        // This is a list of additional columns that will be added to the CRUD. These
  *                                        // will display the column using the title that you have suggested and
  *                                        // Then call the passed method.
  *                                        // call_user_func_array ( $col, array ( $idx, $row[$this->primaryKey] ) )
  *                                        // Passes back the row number and the primary key for this row
  *                                        // Then displays the html that the call back function generates
  *                  'canDelete' => true,  // Optional default: true. If you do not want user to delete rows set to false
  *                  'canUpdate' => true,  // Optional default: true. If you do not want user to update rows set to false
  *                  'canInsert' => true,  // Optional default: true. If you do not want user to insert rows set to false
  *                  'topPager' => true,   // Optional default: true. If you do not want pagination at top, set to false
  *                  'bottomPager' => true,// Optional default: true. If you do not want pagination at bottom, set to false
  *                  'suffix' => '_1',     // Optional default: current CRUD invocation number.
  *                                        // Useful if you have multiple CRUDs on one page. This is the suffix that
  *                                        // is attached to the form variables
  *                  'formAction' => 'view.php?ID=10',
  *                                        // Optional default to ?. On submirt this will return to the current page
  *                  'insDefaults' => array ( 'timestamp' => time() ),
  *                                        // Optional. If there are dfefaults that you wat inserted when the CRUD
  *                                        // inserts a row then you can list them here
  *                  'displayRows' =>10,   // Optional. Sets the number of rows that can be displayed
  *                  'nullsEmpty'  =>false,  // Optional. If this is true then it will put in nulls if the variable is empty
  *                  'dbType'      =>'mysql',// Optional. Tels the system if this is oracle, sqlite or mysql database
  *
  *                  Sort column
  *                  'colSort'      =>'fldStartTime',// Optional. Sets an initial sort column
  *                  'colSortOrder' =>'DESC',// Optional. Sets the direction of the sort column
  *                );
  * </pre>
  */
 public function __construct($tableName, $extraArgs = [])
 {
     parent::__construct();
     $this->log = Log4PHP::logFactory(__CLASS__);
     $this->tableName = $tableName;
     $this->primaryKey = isset($extraArgs['primaryKey']) ? $extraArgs['primaryKey'] : null;
     $this->db = isset($extraArgs['db']) ? $extraArgs['db'] : DB::DEF;
     $this->where = isset($extraArgs['where']) ? $extraArgs['where'] : [];
     $this->extraCols = isset($extraArgs['userCols']) ? $extraArgs['userCols'] : [];
     $this->canDelete = isset($extraArgs['canDelete']) ? $extraArgs['canDelete'] : true;
     $this->canUpdate = isset($extraArgs['canUpdate']) ? $extraArgs['canUpdate'] : true;
     $this->canInsert = isset($extraArgs['canInsert']) ? $extraArgs['canInsert'] : true;
     $this->topPage = isset($extraArgs['topPager']) ? $extraArgs['topPager'] : true;
     $this->bottomPage = isset($extraArgs['bottomPager']) ? $extraArgs['bottomPager'] : true;
     $this->suffix = isset($extraArgs['suffix']) ? $extraArgs['suffix'] : '_' . Invocation::next();
     $this->formAction = isset($extraArgs['formAction']) ? $extraArgs['formAction'] : '?';
     $this->insDefaults = isset($extraArgs['insDefaults']) ? $extraArgs['insDefaults'] : [];
     $this->nullsEmpty = isset($extraArgs['nullsEmpty']) ? $extraArgs['nullsEmpty'] : false;
     $this->dbType = isset($extraArgs['dbType']) ? $extraArgs['dbType'] : DB::driver($this->db);
     $this->action = self::ACTION . $this->suffix;
     $this->delTag = 'D' . $this->suffix;
     $this->updTag = 'U' . $this->suffix;
     $this->gridTag = 'G' . $this->suffix;
     $this->submitId = 'S' . $this->suffix;
     $pageProps = ['suffix' => self::SUFFIX];
     $this->paginator = new Paginator($pageProps);
     $colProps = ['suffix' => self::SUFFIX];
     if (isset($extraArgs['colSort'])) {
         $colProps['init_column'] = $extraArgs['colSort'];
     }
     if (isset($extraArgs['colSortOrder'])) {
         $colProps['init_order'] = $extraArgs['colSortOrder'];
     }
     $this->columnator = new Columnator($colProps);
     $this->resp = new Response();
     if (isset($extraArgs['displayRows'])) {
         $this->paginator->setPageSize($extraArgs['displayRows']);
     }
     if (!$this->getTableMetaData()) {
         return;
     }
     $this->setupDefaultStyle();
     if ($this->paginator->getRows() <= 0) {
         $this->paginator->setRows($this->getRowCount());
     }
     $this->copyVarsFromRequest(Columnator::navVar(self::SUFFIX));
     $this->copyVarsFromRequest(Paginator::navVar(self::SUFFIX));
     $this->copyVarsFromRequest(WebPage::ACTION);
     $this->ok = true;
 }
コード例 #9
0
ファイル: Widget.php プロジェクト: raxisau/JackBooted
    public static function reload($callBack, $url, $numOfSeconds = 20, $css = 'ReloadWidget')
    {
        $id = '_' . Invocation::next();
        $js = <<<JS
            var countDownInterval{$id} = {$numOfSeconds}; //configure refresh interval (in seconds)
            var countDownTime{$id} = countDownInterval{$id} + 1;
            var reloadTimes{$id} = 0;
            var counter{$id};

            function countDown{$id}(){
                countDownTime{$id}--;
                \$('#stop{$id}').show();
                \$('#start{$id}').hide();
                if ( countDownTime{$id} <= 0 ) {
                    clearTimeout(counter{$id});
                    updateReloadArea{$id}();
                    return;
                }
                \$('#countDownText{$id}').html( countDownTime{$id} + '' );
                counter{$id} = setTimeout( "countDown{$id}()", 1000 );
            }

            function stopCount{$id}(){
                clearTimeout(counter{$id})
                \$('#stop{$id}').hide();
                \$('#start{$id}').show();
            }

            function updateReloadArea{$id}(){
                countDownTime{$id} = countDownInterval{$id} + 1;
                reloadTimes{$id} = reloadTimes{$id} + 1;
                \$('#reload{$id}').load('{$url}&R='+reloadTimes{$id}, function() {
                    countDown{$id} ();
                });
            }

            \$().ready ( function () {
                countDown{$id} ();
            });
JS;
        $html = 'Next ' . Tag::hRef("javascript:countDownTime{$id}=0", 'refresh', ['title' => 'Click here to refresh now.', 'class' => $css]) . ' in ' . Tag::hTag('span', ['id' => "countDownText{$id}", 'class' => $css]) . $numOfSeconds . Tag::_hTag('span') . ' seconds ' . Tag::hRef("javascript:stopCount{$id}()", 'Stop', ['id' => "stop{$id}", 'title' => 'Click here to stop the timer.', 'class' => $css]) . Tag::hRef("javascript:countDown{$id}()", 'Start', ['id' => "start{$id}", 'title' => 'Click here to start the timer.', 'class' => $css]) . '<br/>' . Tag::div(['id' => "reload{$id}", 'class' => $css]) . call_user_func($callBack) . Tag::_div();
        return JS::library(JS::JQUERY) . JS::javaScript($js) . $html;
    }
コード例 #10
0
ファイル: Validator.php プロジェクト: raxisau/JackBooted
 /**
  * Creates the Validation object.
  *
  * Requires the form name.
  *
  * @param string $formName The name of the form that will be validated.
  * @param string $suffix The suffix will give the unique identifier if there are a number of
  * validators on a page. The uniquie suffix is automatically generated based on number of
  * invokations of the form. This does not work on ajax late generated forms
  * so for ajax, supply a unique suffix
  *
  * @since 1.0
  */
 public function __construct($formName, $suffix = '')
 {
     parent::__construct();
     if ($suffix == '') {
         $suffix = Invocation::next();
     }
     $this->formName = $formName;
     $this->id = '_' . $suffix;
     $this->setUpJavaScriptFunctions();
 }