0) { $f = fopen($file, 'a'); ob_start(); echo date('Y/m/d H:i:s').' ('.gettype($var).') '.$more_info."\n"; print_r($var); echo "\n\n"; $output = ob_get_clean(); fprintf($f, '%s', $output); fclose($f); } else { echo '
'.date('Y/m/d H:i:s').' ('.gettype($var).') '.$more_info.'
'; echo '
';
            print_r($var);
            echo '
'; } } public function createPage($title=null, $page_name=null) { if (!isset($title)) { $this->title = __('%s mobile', get_product_name()); } else { $this->title = $title; } if (!isset($page_name)) { $this->page_name = 'main_page'; } else { $this->page_name = $page_name; } $this->html = ''; $this->endHeader = false; $this->header = []; $this->endContent = false; $this->content = []; $this->noFooter = false; $this->endFooter = false; $this->footer = []; $this->form = []; $this->grid = []; $this->collapsible = []; $this->endForm = true; $this->endGrid = true; $this->endCollapsible = true; $this->dialog = ''; $this->dialogs = []; } public function showFooter($show=true) { $this->noFooter = !$show; } public function beginHeader() { $this->header = []; $this->header['button_left'] = ''; $this->header['button_right'] = ''; $this->header['title'] = ''; $this->endHeader = false; } public function endHeader() { $this->endHeader = true; } public function createHeader($title=null, $buttonLeft=null, $buttonRight=null) { $this->beginHeader(); $this->headerTitle($title); $this->headerAddButtonLeft($buttonLeft); $this->headerAddButtonRight($buttonRight); $this->endHeader(); } public function headerTitle($title=null) { if (isset($title)) { $this->header['title'] = $title; } } public function headerAddButtonLeft($button=null) { if (isset($button)) { $this->header['button_left'] = $button; } } public function headerAddButtonRight($button=null) { if (isset($button)) { $this->header['button_right'] = $button; } } public function createHeaderButton($options) { return $this->createButton($options); } public function createDefaultHeader($title=false, $left_button=false) { if ($title === false) { $title = __('%s : Mobile', get_product_name()); } if ($left_button === false) { $left_button = $this->createHeaderButton( [ 'icon' => 'ui-icon-logout', 'pos' => 'left', 'text' => __('Logout'), 'href' => 'index.php?action=logout', 'class' => 'header-button-left logout-text', ] ); } $this->createHeader( $title, $left_button, $this->createHeaderButton( [ 'icon' => 'ui-icon-home', 'pos' => 'right', 'text' => __('Home'), 'href' => 'index.php?page=home', 'class' => 'header-button-right', ] ) ); } public function createButton($options) { $return = 'footer = []; $this->endFooter = false; } public function endFooter() { $this->endFooter = true; } public function createFooter($text='') { $this->footerText($text); } public function footerText($text=null) { if (!isset($text)) { $this->footer['text'] = ''; } else { $this->footer['text'] = $text; } $this->endFooter(); } public function defaultFooter() { global $pandora_version, $build_version; if (isset($_SERVER['REQUEST_TIME'])) { $time = $_SERVER['REQUEST_TIME']; } else { $time = get_system_time(); } return "'; } public function beginContent() { $this->content = []; $this->endContent = false; } public function endContent() { $this->endContent = true; } public function contentAddHtml($html) { $this->content[] = $html; } public function contentBeginGrid($mode='responsive') { $this->endGrid = false; $this->grid = []; $this->grid['mode'] = $mode; $this->grid['cells'] = []; } public function contentGridAddCell($html, $key=false) { $k = uniqid('cell_'); if ($key !== false) { $k = $key; } $this->grid['cells'][$k] = $html; } public function contentEndGrid() { $this->endGrid = true; // TODO Make others modes, only responsible mode $convert_columns_jquery_grid = [ 2 => 'a', 3 => 'b', 4 => 'c', 5 => 'd', ]; $convert_cells_jquery_grid = [ 'a', 'b', 'c', 'd', 'e', ]; $html = "
\n"; reset($convert_cells_jquery_grid); foreach ($this->grid['cells'] as $key => $cell) { switch ($this->grid['mode']) { default: case 'responsive': $html .= "
\n"; break; } next($convert_cells_jquery_grid); $html .= "
\n"; $html .= $cell; $html .= "
\n"; $html .= "
\n"; } $html .= "
\n"; $this->contentAddHtml($html); $this->grid = []; } public function contentBeginCollapsible($title=' ', $class='') { $this->endCollapsible = false; $this->collapsible = []; $this->collapsible['items'] = []; $this->collapsible['title'] = $title; $this->collapsible['class'] = $class; } public function contentCollapsibleAddItem($html) { $this->collapsible['items'][] = $html; } public function contentEndCollapsible() { $this->endCollapsible = true; $html = "
\n"; $html .= '

'.$this->collapsible['title']."

\n"; $html .= "\n"; $html .= "
\n"; $this->contentAddHtml($html); $this->collapsible = []; } public function beginForm($action='index.php', $method='post') { $this->form = []; $this->endForm = false; $this->form['action'] = $action; $this->form['method'] = $method; } public function endForm() { $this->contentAddHtml($this->getEndForm()); } public function getEndForm() { $this->endForm = true; $html = "
\n"; foreach ($this->form['fields'] as $field) { $html .= $field."\n"; } $html .= "
\n"; $this->form = []; return $html; } public function formAddHtml($html) { $this->form['fields'][] = $html; } public function formAddInput($options) { $this->formAddHtml($this->getInput($options)); } public function getInput($options) { if (empty($options['name'])) { $options['name'] = uniqid('input'); } if (empty($options['id'])) { $options['id'] = 'text-'.$options['name']; } $html = "
\n"; $html .= "
\n"; if (!empty($options['label'])) { $html .= "\n"; } // Erase other options and only for the input. unset($options['label']); if ($options['type'] === 'password') { $html .= '
'; $options['style'] .= 'background-image: url("'.ui_get_full_url('/').'/images/enable.svg");'; } $html .= ' $value) { $html .= ' '.$option."='".$value."' "; } $html .= ">\n"; if ($options['type'] === 'password') { $html .= '
'; $html .= '
'; $html .= ' '; } $html .= "
\n"; $html .= "
\n"; return $html; } public function formAddInputPassword($options) { $options['type'] = 'password'; $this->formAddInput($options); } public function formAddInputText($options) { $options['type'] = 'text'; $this->formAddInput($options); } public function formAddInputSearch($options) { $options['type'] = 'search'; $this->formAddInput($options); } public function formAddInpuDate($options) { $options['type'] = 'date'; $options['data-clear-btn'] = 'false'; $this->formAddInput($options); } public function formAddCheckbox($options) { $options['type'] = 'checkbox'; if (isset($options['checked'])) { if ($options['checked']) { $options['checked'] = 'checked'; } else { unset($options['checked']); } } $this->formAddInput($options); } public function formAddSubmitButton($options) { $options['type'] = 'submit'; if (isset($options['icon'])) { $options['data-icon'] = $options['icon']; unset($options['icon']); } if (isset($options['icon_pos'])) { $options['data-iconpos'] = $options['icon_pos']; unset($options['icon_pos']); } if (isset($options['text'])) { $options['value'] = $options['text']; unset($options['text']); } $this->formAddInput($options); } public function formAddSelectBox($options) { $html = ''; if (empty($options['name'])) { $options['name'] = uniqid('input'); } if (empty($options['id'])) { $options['id'] = 'select-'.$options['name']; } $html = "
\n"; $html .= "
\n"; if (!empty($options['label'])) { $html .= "\n"; } $html .= "\n"; $html .= "
\n"; $html .= "
\n"; $this->formAddHtml($html); } public function formAddSlider($options) { $options['type'] = 'range'; $this->formAddInput($options); // } public function addDialog($options) { $type = 'hidden'; $dialog_id = uniqid('dialog_'); $dialog_class = ''; $title_close_button = false; $title_text = ''; $content_id = uniqid('content_'); $content_class = ''; $content_text = ''; $button_close = true; $button_text = __('Close'); if (is_array($options)) { if (isset($options['type'])) { $type = $options['type']; } if (isset($options['dialog_id'])) { $dialog_id = $options['dialog_id']; } if (isset($options['dialog_class'])) { $dialog_class = $options['dialog_class']; } if (isset($options['title_close_button'])) { $title_close_button = $options['title_close_button']; } if (isset($options['title_text'])) { $title_text = $options['title_text']; } if (isset($options['content_id'])) { $content_id = $options['content_id']; } if (isset($options['content_class'])) { $content_class = $options['content_class']; } if (isset($options['content_text'])) { $content_text = $options['content_text']; } if (isset($options['button_close'])) { $button_close = $options['button_close']; } if (isset($options['button_text'])) { $button_text = $options['button_text']; } } $html_title_close_button = ''; if ($title_close_button) { $html_title_close_button = "data-close-btn='yes'"; } $dialogHtml = "
\n"; $dialogHtml .= "
\n"; $dialogHtml .= "

".$title_text."

\n"; $dialogHtml .= "
\n"; $dialogHtml .= "
\n"; $dialogHtml .= $content_text; if ($button_close) { $dialogHtml .= ""; if (empty($button_text)) { $dialogHtml .= __('Close'); } else { $dialogHtml .= $button_text; } $dialogHtml .= "

\n"; } $dialogHtml .= "
\n"; $dialogHtml .= "
\n"; if ($options['return_html_dialog'] === true) { return $dialogHtml; } $this->dialogs[$type][] = $dialogHtml; } public function showError($msg) { echo $msg; } public function showPage() { if (!$this->endHeader) { $this->showError(__('Not found header.')); } else if (!$this->endContent) { $this->showError(__('Not found content.')); } else if ((!$this->endFooter) && (!$this->noFooter)) { $this->showError(__('Not found footer.')); } else if (!$this->endForm) { $this->showError(__('Incorrect form.')); } else if (!$this->endGrid) { $this->showError(__('Incorrect grid.')); } else if (!$this->endCollapsible) { $this->showError(__('Incorrect collapsible.')); } ob_start(); echo "\n"; echo "\n"; echo " \n"; echo ' '.$this->title."\n"; echo " \n"; echo " \n"; echo ' '."\n"; echo ' '."\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $loaded = []; foreach ($this->cssList as $filename) { if (in_array($filename, $loaded) === true) { continue; } array_push($loaded, $filename); $url_css = ui_get_full_url($filename, false, false, false); echo ''."\n\t"; } $js_loaded = []; foreach ($this->jsList as $filename) { if (in_array($filename, $js_loaded) === true) { continue; } array_push($js_loaded, $filename); $url_css = ui_get_full_url($filename, false, false, false); echo ''."\n\t"; } echo " \n"; echo " \n"; echo include_javascript_dependencies_flot_graph(false, false); echo "
"; if (!empty($this->dialogs)) { if (!empty($this->dialogs['onStart'])) { foreach ($this->dialogs['onStart'] as $dialog) { echo ' '.$dialog."\n"; } } } echo "
\n"; echo "
\n"; echo '

'.$this->header['title']."

\n"; echo ' '.$this->header['button_left']."\n"; echo ' '.$this->header['button_right']."\n"; echo "
\n"; echo "
\n"; foreach ($this->content as $content) { echo ' '.$content."\n"; } echo "
\n"; if (!$this->noFooter) { echo "
\n"; if (!empty($this->footer['text'])) { echo ' '.$this->footer['text']."\n"; } else { echo ' '.$this->defaultFooter()."\n"; } } echo "
\n"; echo "
\n"; if (!empty($this->dialogs)) { if (!empty($this->dialogs['hidden'])) { foreach ($this->dialogs['hidden'] as $dialog) { echo ' '.$dialog."\n"; } } } echo ""; echo " \n"; echo ''; ob_end_flush(); } // Add a listener to set a link when a row of a table is clicked. // The target link will be the first tag found into the row public function contentAddLinkListener($table_name) { $this->contentAddHtml( '' ); } /** * Add CSS file to be loaded. * * @param string $name Css file name, as in ui_require_css. * @param string $path Path where search for css file. * * @return boolean True if success, False if not. */ public function require_css( string $name, string $path='include/styles/' ):bool { $filename = $path.$name.'.css'; $system = System::getInstance(); if (file_exists($filename) === false && file_exists($system->getConfig('homedir').'/'.$filename) === false && file_exists($system->getConfig('homedir').'/'.ENTERPRISE_DIR.'/'.$filename) === false ) { return false; } if (in_array($filename, $this->cssList) === false) { $this->cssList[] = $filename; } return true; } /** * Add JS file to be loaded. * * @param string $name JAvascript file name, as in * \ui_require_javascript_file. * @param string $path Path where search for Javascript file. * * @return boolean True if success, False if not. */ public function require_javascript( string $name, string $path='include/javascript/' ):bool { $filename = $path.$name.'.js'; $system = System::getInstance(); if (file_exists($filename) === false && file_exists($system->getConfig('homedir').'/'.$filename) === false && file_exists($system->getConfig('homedir').'/'.ENTERPRISE_DIR.'/'.$filename) === false ) { return false; } if (in_array($filename, $this->jsList) === false) { $this->jsList[] = $filename; } return true; } /** * Forces reload to retrieve with and height. * * @return void */ public function retrieveViewPort() { ?> contentAddHtml( '' ); } } class Table { private $head = []; private $rows = []; public $id = ''; private $rowClass = []; private $class_table = ''; private $row_heads = []; public $row_keys_as_head_row = false; public function __construct() { $this->init(); } public function init() { $this->id = uniqid(); $this->head = []; $this->rows = []; $this->rowClass = []; $this->class_table = ''; $this->row_heads = []; $this->row_keys_as_head_row = false; } public function addHeader($head) { $this->head = $head; } public function addRowHead($key, $head_text) { $this->row_heads[$key] = $head_text; } public function addRow($row=[], $key=false) { if ($key !== false) { $this->rows[$key] = $row; } else { $this->rows[] = $row; } } public function importFromHash($data) { foreach ($data as $id => $row) { $table_row = []; foreach ($row as $key => $value) { if (!in_array($key, $this->head)) { $this->head[] = $key; } $cell_key = array_search($key, $this->head); $table_row[$cell_key] = $value; } $this->rows[$id] = $table_row; } } public function importFromHashEvents($data) { foreach ($data as $id => $row) { $table_row = []; foreach ($row as $key => $value) { if (!in_array($key, $this->head)) { // $this->head[] = $key; } // $cell_key = array_search($key, $this->head); // $table_row[$cell_key] = $value; $table_row[$key] = $value; } $this->rows[$id] = $table_row; } } public function setClass($class='') { $this->class_table = $class; } public function setId($id=false) { if (empty($id)) { $this->id = uniqid(); } else { $this->id = $id; } } public function setRowClass($class='', $pos=false) { if (is_array($class)) { $this->rowClass = $class; } else { if ($pos !== false) { $this->rowClass[$pos] = $class; } else { $this->rowClass = array_fill(0, count($this->rows), $class); } } } public function getHTML() { $html = ''; $html = ""; if ($this->head) { $html .= ''; $html .= ''; // Empty head for white space between rows in the responsive vertical layout // ~ $html .= ""; foreach ($this->head as $head) { $html .= "'; } $html .= ''; $html .= ''; } $html .= ''; foreach ($this->rows as $key => $row) { $class = ''; if (isset($this->rowClass[$key])) { $class = $this->rowClass[$key]; } $html .= ""; // Empty head for white space between rows in the responsive vertical layout foreach ($row as $key_cell => $cell) { $html .= "'; } $html .= ''; } $html .= ''; $html .= '
".$head.'
".$cell.'
'; return $html; } }