コード例 #1
0
 public static function test_sqlite3_json_flexigrid($flexigrid_page, $flexigrid_resperpage, $flexigrid_sortfld, $flexigrid_sortdir, $flexigrid_srcby, $flexigrid_search, $flexigrid_xsrcby, $flexigrid_xsearch)
 {
     //-- ensure the correct types
     $flexigrid_page = (int) $flexigrid_page;
     $flexigrid_resperpage = (int) $flexigrid_resperpage;
     $flexigrid_srcby = (string) $flexigrid_srcby;
     $flexigrid_search = (string) $flexigrid_search;
     $flexigrid_xsrcby = (string) $flexigrid_xsrcby;
     $flexigrid_xsearch = (string) $flexigrid_xsearch;
     $flexigrid_sortfld = (string) $flexigrid_sortfld;
     $flexigrid_sortdir = (string) $flexigrid_sortdir;
     //--
     //-- db init
     $model = new SmartTestSQLite3Model();
     if (!is_object($model)) {
         return Smart::json_encode(array('error' => 'Flexigrid JSON DB Object Failed to initialize'));
     }
     //end if
     //--
     //-- where management (we have 2 situations: 1st is normal search ; 2nd is search by starting letter)
     if ((string) $flexigrid_srcby != '' and (string) $flexigrid_search != '') {
         //-- normal search (by field and value)
         $where_field = $flexigrid_srcby;
         $where_value = $flexigrid_search;
         $where_mode = '';
         //--
     } else {
         //-- search by starting letters
         $where_field = $flexigrid_xsrcby;
         $where_value = $flexigrid_xsearch;
         $where_mode = 'letters';
         //--
     }
     //end if else
     //--
     //-- output data init
     $jsonData = array('page' => $flexigrid_page, 'total' => $model->table_flexigrid_count($where_field, $where_value, $where_mode), 'rows' => array());
     //--
     //-- read data
     $rows = $model->table_flexigrid_read($where_field, $where_value, $where_mode, $flexigrid_sortfld, $flexigrid_sortdir, $flexigrid_resperpage, $flexigrid_page);
     //--
     if (is_array($rows)) {
         foreach ($rows as $row) {
             //--
             $entry = array('id' => 'ID_' . $row['iso'], 'cell' => array('iso' => $row['iso'], 'name' => $row['name'], 'printable_name' => $row['printable_name'], 'iso3' => $row['iso3'], 'numcode' => $row['numcode']));
             //--
             $jsonData['rows'][] = $entry;
             //--
         }
         //end foreach
     }
     //end if
     //--
     //--
     return Smart::json_encode($jsonData);
     //--
 }
コード例 #2
0
 /**
  * Answer Post Form by Ajax
  *
  * NOTICE:
  * - if OK: and redirect URL have been provided, the replace div is not handled
  * - if ERROR: no replace div or redirect is handled
  *
  * @param 	$y_status 			OK / ERROR
  * @param 	$y_title 			Dialog Title
  * @param 	$y_message 			Dialog Message (Optional in the case of OK)
  * @param 	$y_redirect_url 	**OPTIONAL** URL to redirect in the case of OK
  * @param 	$y_replace_div 		**OPTIONAL** The ID of the DIV to Replace
  * @param 	$y_replace_html 	**OPTIONAL** the HTML Code to replace in DIV
  *
  * @return STRING				[javascript code]
  *
  */
 public static function post_answer_by_ajax($y_status, $y_title, $y_message, $y_redirect_url = '', $y_replace_div = '', $y_replace_html = '')
 {
     //--
     $translator_core_messages = SmartTextTranslations::getTranslator('@core', 'messages');
     //--
     if ((string) $y_status == 'OK') {
         $y_status = 'OK';
         $button_text = $translator_core_messages->text('ok');
     } else {
         $y_status = 'ERROR';
         $button_text = $translator_core_messages->text('cancel');
     }
     //end if else
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $y_redirect_url = '';
         // avoid redirect if DEBUG IS ON to catch the debug messages ...
     }
     //end if
     //--
     return Smart::json_encode(array('completed' => 'DONE', 'status' => $y_status, 'action' => $button_text, 'title' => $y_title, 'message' => base64_encode($y_message), 'redirect' => $y_redirect_url, 'replace_div' => $y_replace_div, 'replace_html' => base64_encode($y_replace_html)));
     //--
 }
コード例 #3
0
 private static function replace_marker($mtemplate, $key, $val)
 {
     //--
     if ((string) $key != '' and preg_match('/^[A-Z0-9_\\-\\.]+$/', (string) $key) and strpos((string) $mtemplate, '[####' . $key) !== false) {
         //--
         $regex = '/\\[####' . preg_quote((string) $key, '/') . '(\\|bool|\\|num|\\|htmid|\\|jsvar|\\|json)?(\\|url)?(\\|js)?(\\|html)?(\\|nl2br)?' . '####\\]/';
         //--
         if ((string) $val != '') {
             $val = (string) str_replace(array('[####', '####]', '[%%%%', '%%%%]', '[@@@@', '@@@@]'), array('(####+', '+####)', '(%%%%+', '+%%%%)', '(@@@@+', '+@@@@)'), (string) $val);
             // protect against cascade / recursion / undefined variables - for content injections of: variables / syntax / sub-templates
         }
         //end if
         //--
         $mtemplate = (string) preg_replace_callback((string) $regex, function ($matches) use($val) {
             //-- Format
             if ((string) $matches[1] == '|num') {
                 // Number
                 $val = (string) (double) $val;
             } elseif ((string) $matches[1] == '|bool') {
                 // Boolean
                 if ($val) {
                     $val = 'true';
                 } else {
                     $val = 'false';
                 }
                 //end if else
             } elseif ((string) $matches[1] == '|htmid') {
                 // HTML ID
                 $val = (string) trim((string) preg_replace('/[^a-zA-Z0-9_\\-]/', '', (string) $val));
             } elseif ((string) $matches[1] == '|jsvar') {
                 // JS Variable
                 $val = (string) trim((string) preg_replace('/[^a-zA-Z0-9_]/', '', (string) $val));
             } elseif ((string) $matches[1] == '|json') {
                 // Json Data (!!! DO NOT ENCLOSE IN ' or " as it can contain them as well as it can be [] or {} ... this is pure JSON !!!)
                 $val = (string) Smart::json_encode($val, false, false);
                 // no pretty print, escape unicode as it is served inline !
             }
             //end if
             //-- Escape
             if ((string) $matches[2] == '|url') {
                 $val = (string) Smart::escape_url((string) $val);
             }
             //end if
             if ((string) $matches[3] == '|js') {
                 $val = (string) Smart::escape_js((string) $val);
             }
             //end if
             if ((string) $matches[4] == '|html') {
                 $val = (string) Smart::escape_html((string) $val);
             }
             //end if
             //--
             if ((string) $matches[5] == '|nl2br') {
                 $val = (string) Smart::nl_2_br((string) $val);
             }
             //end if
             //--
             return (string) $val;
             //--
         }, (string) $mtemplate);
         //--
     }
     //end if
     //--
     return (string) $mtemplate;
     //--
 }
コード例 #4
0
 public static function test_sqlite3_json_smartgrid($ofs, $sortby, $sortdir, $sorttype, $src = '')
 {
     //--
     $db = new SmartTestSQLite3Model();
     $model = $db->getConnection();
     //--
     //--
     $data = array();
     $data['status'] = 'OK';
     $data['crrOffset'] = (int) $ofs;
     $data['itemsPerPage'] = 25;
     $data['sortBy'] = (string) $sortby;
     $data['sortDir'] = (string) $sortdir;
     $data['sortType'] = (string) $sorttype;
     $data['filter'] = array('src' => (string) $src);
     //--
     if ((string) strtoupper((string) $sortdir) == 'DESC') {
         $syntax_sort_dir = 'DESC';
     } else {
         $syntax_sort_dir = 'ASC';
     }
     //end if else
     $syntax_sort_mode = '';
     switch ((string) $sortby) {
         case 'iso':
             $syntax_sort_mode = ' ORDER BY iso ' . $syntax_sort_dir;
             break;
         case 'name':
             $syntax_sort_mode = ' ORDER BY name ' . $syntax_sort_dir;
             break;
         case 'iso3':
             $syntax_sort_mode = ' ORDER BY iso3 ' . $syntax_sort_dir;
             break;
         case 'numcode':
             $syntax_sort_mode = ' ORDER BY numcode ' . $syntax_sort_dir;
             break;
         default:
             $syntax_sort_mode = '';
     }
     //end switch
     //--
     $where = '';
     if ((string) $src != '') {
         if (is_numeric($src)) {
             $where = $model->prepare_param_query(' WHERE numcode = ?', array((int) $src));
         } elseif (strlen((string) $src) == 2) {
             $where = $model->prepare_param_query(' WHERE iso = ?', array(SmartUnicode::str_toupper($src)));
         } elseif (strlen((string) $src) == 3) {
             $where = $model->prepare_param_query(' WHERE iso3 = ?', array(SmartUnicode::str_toupper($src)));
         } else {
             $where = $model->prepare_param_query(' WHERE name LIKE ?', array($src . '%'));
         }
         //end if else
     }
     //end if
     $data['totalRows'] = $model->count_data('SELECT COUNT(1) FROM sample_countries' . $where);
     $data['rowsList'] = $model->read_adata('SELECT iso, name, iso3, numcode FROM sample_countries' . $where . $syntax_sort_mode . ' LIMIT ' . (int) $data['itemsPerPage'] . ' OFFSET ' . (int) $data['crrOffset']);
     //--
     unset($db);
     // close
     //--
     //--
     return Smart::json_encode((array) $data);
     //--
 }
コード例 #5
0
 public function Run()
 {
     //--
     require_once 'lib/core/lib_smart_test_suite.php';
     // test suite
     //--
     //--
     SmartSession::start();
     // start the session
     //--
     //--
     if (SmartPersistentCache::isActive()) {
         SmartPersistentCache::getKey('test-unit', 'version');
         // just test if redis re-uses the connection ...
     }
     //end if
     //--
     //--
     $op = $this->RequestVarGet('op', 'testunit.main', 'string');
     //--
     switch ((string) $op) {
         case 'testunit.phpinfo':
             //--
             $this->PageViewSetCfg('rawpage', true);
             ob_start();
             phpinfo();
             $main = ob_get_contents();
             ob_end_clean();
             break;
         case 'testunit.captcha':
             //--
             $this->PageViewSetCfg('rawpage', 'yes');
             // should work both: true or 'yes'
             $this->PageViewSetCfg('rawmime', 'image/png');
             $this->PageViewSetCfg('rawdisp', 'inline');
             $main = SmartTestSuite::test_captcha('png');
             //--
             break;
         case 'testunit.post-form-by-ajax':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::post__answer__by__ajax($this->RequestVarGet('tab'), $this->RequestVarGet('frm'));
             //--
             break;
         case 'testunit.strings-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_strings();
             //--
             break;
         case 'testunit.crypto-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_crypto();
             //--
             break;
         case 'testunit.filesys-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_fs();
             //--
             break;
         case 'testunit.pgsql-server-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_pgsqlserver();
             //--
             break;
         case 'testunit.redis-server-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_redisserver();
             //--
             break;
         case 'testunit.json-sqlite3-smartgrid':
             //--
             $this->PageViewSetCfg('rawpage', true);
             //--
             $ofs = $this->RequestVarGet('ofs', 0, 'integer+');
             $sortby = $this->RequestVarGet('sortby', 'id', 'string');
             $sortdir = $this->RequestVarGet('sortdir', 'ASC', 'string');
             $sorttype = $this->RequestVarGet('sorttype', 'text', 'string');
             $src = $this->RequestVarGet('src', '', 'string');
             // filter var
             //--
             $main = SmartTestSuite::test_sqlite3_json_smartgrid($ofs, $sortby, $sortdir, $sorttype, $src);
             //--
             break;
         case 'testunit.html-editor':
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = SmartComponents::js_init_away_page();
             $main .= SmartComponents::js_init_html_area();
             $main .= SmartComponents::js_draw_html_area('test_html_area', 'test_html_area', '', '920px', '500px');
             $main .= '<button class="ux-button" onClick="alert($(\'#test_html_area\').val());">Get HTML Source</button>';
             //--
             break;
         case 'testunit.code-editor':
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = SmartComponents::js_init_away_page('The changes will be lost !');
             $main .= SmartComponents::js_init_editarea();
             $main .= SmartComponents::js_draw_editarea('test_code_editor', 'test_code_editor', '', 'html', true, '920px', '450px');
             //--
             break;
         case 'testunit.load-url-or-file':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::load__url__or__file('http://www.unix-world.org');
             //--
             break;
         case 'testunit.barcodes-qrcode':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode2d_qrcode();
             //--
             break;
         case 'testunit.barcodes-semcode':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode2d_datamatrix();
             //--
             break;
         case 'testunit.barcodes-pdf417':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode2d_pdf417();
             //--
             break;
         case 'testunit.barcodes-code128':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_128B();
             //--
             break;
         case 'testunit.barcodes-code93':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_93();
             //--
             break;
         case 'testunit.barcodes-code39':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_39();
             //--
             break;
         case 'testunit.barcodes-rm4kix':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_kix();
             //--
             break;
         case 'testunit.charts-biz':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $this->PageViewSetCfg('expires', 120);
             // cache expire test
             //--
             $chart = new SmartImgBizCharts('matrix', 'Marketing Chart', array('Chart 1' => array('red label' => array('x' => Smart::random_number(5, 7), 'y' => Smart::random_number(100, 120), 'z' => Smart::random_number(45, 75), 'color' => '#FF3300'), 'blue' => array('x' => Smart::random_number(100, 115), 'y' => Smart::random_number(200, 210), 'z' => Smart::random_number(20, 50), 'color' => '#003399'), 'green' => array('x' => Smart::random_number(150, 175), 'y' => Smart::random_number(250, 270), 'z' => Smart::random_number(2, 8), 'color' => '#33CC33', 'labelcolor' => '#11AA11'), 'yellow' => array('x' => Smart::random_number(400, 420), 'y' => Smart::random_number(70, 90), 'z' => Smart::random_number(50, 90), 'color' => '#FFCC00'), 'default' => array('x' => Smart::random_number(300, 325), 'y' => Smart::random_number(300, 320)))), 'png');
             $chart->width = 500;
             $chart->height = 500;
             $chart->axis_x_label = 'Relative Market Share';
             $chart->axis_y_label = 'Market Growth Rate';
             //--
             $this->PageViewSetCfg('rawmime', $chart->mime_header());
             $this->PageViewSetCfg('rawdisp', $chart->disposition_header());
             $main = $chart->generate();
             //--
             break;
         case 'testunit.charts-gfx':
             //--
             $this->PageViewSetCfg('rawpage', true);
             //--
             $showgraph2 = Smart::random_number(0, 1);
             $showgraphdepths = Smart::random_number(0, 1);
             $showtype = Smart::random_number(1, 6);
             switch ((string) $showtype) {
                 case 1:
                     $mode = 'vbars';
                     break;
                 case 2:
                     $mode = 'hbars';
                     break;
                 case 3:
                     $mode = 'dots';
                     break;
                 case 4:
                     $mode = 'lines';
                     break;
                 case 5:
                     $mode = 'pie';
                     break;
                 case 6:
                 default:
                     $mode = 'donut';
             }
             //end if
             //--
             $chart = new SmartImgGfxCharts($mode, "Type [" . $mode . "]", array(array('x' => "white", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 10, 'v' => '#ECECEC'), array('x' => "red", 'y' => 22.45, 'z' => Smart::random_number(10, 90), 'w' => 25, 'v' => '#FF3300'), array('x' => "blue", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 7, 'v' => '#003399'), array('x' => "yellow", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 17, 'v' => '#FFCC00'), array('x' => "green", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 31, 'v' => '#33CC33'), array('x' => "black", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 17, 'v' => '#333333')), 'png', $showgraph2, $showgraphdepths);
             $chart->axis_x = 'X-Axis';
             $chart->axis_y = 'Y-Axis';
             //--
             $this->PageViewSetCfg('rawmime', $chart->mime_header());
             $this->PageViewSetCfg('rawdisp', $chart->disposition_header());
             $main = $chart->generate();
             //--
             break;
         case 'testunit.ods':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $oo = new SmartExportToOpenOffice();
             $this->PageViewSetCfg('rawmime', $oo->ODS_Mime_Header());
             $this->PageViewSetCfg('rawdisp', $oo->ODS_Disposition_Header('myfile.ods', 'attachment'));
             $main = $oo->ODS_SpreadSheet('A Table', array('<column 1>', 'column " 2', 'column & 3'), array('data 1.1', 'data 1.2', 1.3, 'data 2.1', 'data 2.2', 2.31), array('', '', 'decimal4'));
             //--
             break;
         case 'testunit.json-test':
             //--
             $mixed_data = ['Unicode Text' => '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド\'#@<tag>!$%^&*()-_=+' . "\r\n\t" . '</tag>', 'Numbers' => 1234567890.99, 'Boolean TRUE:' => true, 'Boolean FALSE:' => false];
             //--
             $main = '<h1> Json Test</h1>';
             $main .= '<pre style="background:#ECECEC; border:1px solid #CCCCCC; line-height:32px; padding:8px;">';
             $main .= '<b>Default (Unicode Unescaped) Json:</b>' . "\n" . Smart::json_encode($mixed_data) . "\n";
             $main .= '<hr>';
             $main .= '<b>Default (Unicode Unescaped) Json / Pretty Print:</b>' . "\n" . Smart::json_encode($mixed_data, true) . "\n";
             $main .= '<hr>';
             $main .= '<b>Unicode Escaped Json:</b>' . "\n" . Smart::json_encode($mixed_data, false, false) . "\n";
             $main .= '<hr>';
             $main .= '<b>Unicode Escaped Json / Pretty Print:</b>' . "\n" . Smart::json_encode($mixed_data, true, false) . "\n";
             $main .= '</pre>';
             //--
             break;
         case 'testunit.interractions':
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = SmartTestSuite::test_interractions($this->RequestVarGet('mode'));
             //--
             break;
         case 'testunit.autocomplete':
             //--
             $src = $this->RequestVarGet('src', '', 'string');
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_sqlite3_json_autocomplete($src);
             //--
             break;
         case 'testunit.main':
             //--
             $is_modal = false;
             if ($this->IfRequestModalPopup() or $this->IfRequestPrintable()) {
                 $is_modal = true;
                 $this->PageViewSetCfg('template-file', 'template-modal.htm');
             }
             //end if
             //--
             $main = SmartTestSuite::main_screen($this->RequestVarGet('tab'), $this->RequestVarGet('frm'), $this->RequestVarGet('testformdata'));
             //--
             if (!$is_modal) {
                 SmartTestSuite::test_load_libs();
                 // just for testing all libs
                 if ($this->IfDebug()) {
                     $this->SetDebugData('TestUnit.Main', 'Loading all staticload libs at once for test purposes ...');
                 }
                 //end if
             }
             //end if
             //--
             break;
         default:
             //--
             $this->PageViewSetCfg('error', 'Invalid TestUnit Operation ! ...');
             return 400;
             //--
     }
     //end switch
     //--
     //--
     $this->PageViewSetVars(array('title' => 'Test Suite', 'main' => $main));
     //--
 }