Ejemplo n.º 1
0
 public function get_field($id)
 {
     $f = false;
     if ($this->change) {
         $this->db->change('bbn');
     }
     if (is_string($id) && strpos($id, '.') && ($x = explode('.', $id)) && count($x) === 2 && \bbn\str\text::check_name($x[0], $x[1])) {
         $id = $this->get_var("\n\t\t\t\tSELECT bbn_fields.id\n\t\t\t\tFROM bbn_fields\n\t\t\t\t\tJOIN bbn_smenus\n\t\t\t\t\t\tON bbn_smenus.bbn_id_site = {$this->id}\n\t\t\t\t\t\tAND bbn_smenus.bbn_name LIKE '{$x['0']}'\n\t\t\t\tWHERE bbn_fields.bbn_name LIKE '{$x['1']}'\n\t\t\t\tLIMIT 1");
     }
     if (is_int($id) || ctype_digit($id)) {
         if ($tmp = $this->db->get_row("\n        SELECT id, bbn_position, bbn_name, bbn_tit, bbn_id_form, bbn_mand\n        FROM bbn_fields\n        WHERE bbn_fields.id = ?\n        AND bbn_id_site = ?\n        LIMIT 1", $id, $this->id)) {
             $f = new \stdClass();
             foreach ($tmp as $k => $v) {
                 if (substr($k, 0, 4) === 'bbn_') {
                     $k = substr($k, 4);
                 }
                 $f->{$k} = $v;
             }
             $f->params = array();
             $r = $this->db->query("\n\t\t\t\t\tSELECT bbn_value, \n\t\t\t\t\tIFNULL(bbn_smenus.bbn_name,'') AS reftable,\n\t\t\t\t\tIFNULL(bbn_fields.bbn_name,'') AS reffield\n\t\t\t\t\tFROM bbn_param\n\t\t\t\t\t\tLEFT OUTER JOIN bbn_fields\n\t\t\t\t\t\t\tON bbn_fields.id = bbn_value\n\t\t\t\t\t\tLEFT OUTER JOIN bbn_smenus\n\t\t\t\t\t\t\tON bbn_fields.bbn_id_smenu = bbn_smenus.id\n\t\t\t\t\tWHERE bbn_id_field = %u\n\t\t\t\t\tORDER BY bbn_param.bbn_position", $f->id);
             while ($d = $r->get_row()) {
                 array_push($f->params, empty($d['reftable']) ? $d['bbn_value'] : $d['reftable'] . '.' . $d['reffield']);
             }
         }
     }
     if ($this->change) {
         $this->db->change($this->change);
     }
     return $f;
 }
Ejemplo n.º 2
0
 public function log()
 {
     $ar = func_get_args();
     $cn = \bbn\str\text::encode_filename(str_replace('\\', '_', get_class($this)));
     foreach ($ar as $a) {
         \bbn\tools::log($a, $cn);
     }
 }
Ejemplo n.º 3
0
 private function parseCMD($st)
 {
     if (!mb_detect_encoding($st)) {
         $st = utf8_encode($st);
     }
     $tmp = explode("\n", $st);
     $res = [];
     foreach ($tmp as $t) {
         $i = strpos($t, ':');
         if ($i > 0) {
             $res[\bbn\str\text::change_case(\bbn\str\text::encode_filename(substr($t, 0, $i)), 'lower')] = trim(substr($t, $i + 1));
         }
     }
     return $res;
 }
Ejemplo n.º 4
0
 /**
  * @return void 
  */
 public function __construct(array $cfg, $price, $email, $ref, $currency = 'EUR')
 {
     if (isset($cfg['site'], $cfg['rang'], $cfg['id'], $cfg['key'], $cfg['pass']) && is_numeric($price) && $price > 0 && \bbn\str\text::is_email($email) && $this->check_server()) {
         if (isset(self::$currencies[$currency])) {
             $this->currency = self::$currencies[$currency];
             $this->price = $price * 100;
             $this->email = $email;
             $this->binkey = pack("H*", $cfg['key']);
             $this->ref = $ref;
             $this->cfg = $cfg;
             $this->enc = self::$encryptions[array_rand(self::$encryptions)];
             $this->time = date('c');
             $this->params = array('PBX_SITE' => $this->cfg['site'], 'PBX_RANG' => $this->cfg['rang'], 'PBX_IDENTIFIANT' => $this->cfg['id'], 'PBX_TOTAL' => $this->price, 'PBX_DEVISE' => $this->currency, 'PBX_CMD' => $this->ref, 'PBX_PORTEUR' => $this->email, 'PBX_RETOUR' => 'Total:M;nomSession:R;NumAutorisation:A;NumTransaction:T;TypeCarte:C;Erreur:E', 'PBX_REPONDRE_A' => self::$url_reponse, 'PBX_HASH' => $this->enc, 'PBX_TIME' => $this->time);
             $this->process();
             $this->online = 1;
         }
     }
 }
Ejemplo n.º 5
0
 private static function define($dbs, $dbs_table = '')
 {
     if (empty($dbs)) {
         $dbs = self::$default_cfg;
     } else {
         if (is_string($dbs)) {
             $db = $dbs;
             $dbs = self::$default_cfg;
             $dbs['db'] = $db;
         }
     }
     if (!self::$dbs) {
         self::$dbs = $dbs;
     }
     if (!empty($dbs_table)) {
         self::$dbs_table = $dbs_table;
     }
     if (!\bbn\str\text::check_name(self::$dbs_table)) {
         self::log("Table name not allowed", self::$dbs_table);
         die("Table name not allowed");
     }
 }
Ejemplo n.º 6
0
 public static function last_day_of_month($date, $format = false)
 {
     if ($date) {
         $m = false;
         if (\bbn\str\text::is_number($date)) {
             if ($date <= 12) {
                 $m = $date;
                 $y = date('Y');
             } else {
                 $m = (int) date('m', $date);
                 $y = date('Y', $date);
             }
         } else {
             if ($d = strtotime($date)) {
                 $m = (int) date('m', $d);
                 $y = date('Y', $d);
             }
         }
         if ($m) {
             $r = mktime(0, 0, -1, $m + 1, 1, $y);
             return $format ? date($format, $r) : $r;
         }
     }
 }
Ejemplo n.º 7
0
 public function __construct(array $cfg)
 {
     if (isset($cfg['primary'])) {
         $this->id = isset($cfg['id']) ? $cfg['id'] : \bbn\str\text::genpwd();
         $this->primary = $cfg['primary'];
         if (!isset($cfg['builder'])) {
             $cfg['builder'] = new \bbn\html\builder();
         }
         $this->builder = $cfg['builder'];
         $this->grid = new \Kendo\UI\Grid($this->id);
         $this->dataSource = new \Kendo\Data\DataSource();
         if (isset($cfg['data'])) {
             $this->dataSource->data($cfg['data']);
         }
         $this->schema = new \Kendo\Data\DataSourceSchema();
         $this->schema->data('data');
         $this->schema->total('total');
         $this->model = new \Kendo\Data\DataSourceSchemaModel();
         $this->model->id($cfg['primary']);
         foreach ($cfg['elements'] as $e) {
             if (isset($e['attr']['name'])) {
                 $field = new \Kendo\Data\DataSourceSchemaModelField($e['attr']['name']);
                 if (isset($e['attr']['name']) && isset($e['editable']) && $e['editable']) {
                     if (isset($e['type'])) {
                         $field->type($e['type']);
                     }
                     if (isset($e['null']) && $e['null']) {
                         $field->nullable(true);
                     }
                     if (isset($e['attr']['readonly']) && $e['attr']['readonly']) {
                         $field->editable(false);
                     } else {
                         if (isset($e['validation'])) {
                             $field->validation($e['validation']);
                         }
                     }
                     $this->model->addField($field);
                 }
                 if (empty($e['editable'])) {
                     $field->editable(false);
                 }
                 if (!empty($e['default'])) {
                     $field->defaultValue($e['default']);
                 }
             }
             $col = new \Kendo\UI\GridColumn();
             if (!isset($e['field']) || $e['field'] !== 'hidden') {
                 if (isset($e['editable']) && $e['editable']) {
                     /*
                                 if ( !isset($e['editor']) ){
                      $input = $this->builder->input($e, 1);
                      $sc = $input->ele_and_script();
                      $e['editor'] = new \Kendo\JavaScriptFunction('function(container, options) {
                        '.$sc[0].'.appendTo(container)'.$sc[1].'
                      }');
                                 }
                                 $col->editor($e['editor']);
                     * 
                     */
                 }
                 if (isset($e['raw'])) {
                     $col->encoded(false);
                 }
                 if (isset($e['data'])) {
                     $col->values($e['data']);
                 }
                 if (isset($e['label'])) {
                     $col->title($e['label']);
                 }
                 if (isset($e['attr']['name'])) {
                     $col->field($e['attr']['name']);
                 }
                 if (isset($e['width'])) {
                     $col->width((int) $e['width']);
                 }
                 if (isset($e['format'])) {
                     $col->format('{0:' . $e['format'] . '}');
                 }
                 if (isset($e['hidden'])) {
                     $col->hidden(true);
                 }
                 if (isset($e['template'])) {
                     $col->template($e['template']);
                 }
                 if (isset($e['editor'])) {
                     $col->editor($e['editor']);
                 }
                 if (isset($e['encoded'])) {
                     $col->encoded($e['encoded']);
                 }
                 if (isset($e['commands'])) {
                     foreach ($e['commands'] as $c) {
                         if (isset($c['click'])) {
                             $c['click'] = new \Kendo\JavaScriptFunction($c['click']);
                         }
                         $col->addCommandItem($c);
                     }
                 }
                 if (count(\bbn\tools::to_array($col)) > 0) {
                     $this->grid->addColumn($col);
                 }
             }
         }
         if (isset($cfg['url'])) {
             $this->transport = new \Kendo\Data\DataSourceTransport();
             if (isset($cfg['all'])) {
                 $this->set_all($cfg['url']);
             } else {
                 if (isset($cfg['select'])) {
                     $this->set_select($cfg['select'] === 1 || $cfg['select'] === 'on' ? 'json/select/' . $cfg['url'] : $cfg['select']);
                 }
                 if (isset($cfg['insert'])) {
                     $this->set_insert($cfg['insert'] === 1 || $cfg['insert'] === 'on' ? 'json/insert/' . $cfg['url'] : $cfg['insert']);
                 }
                 if (isset($cfg['update'])) {
                     $this->set_update($cfg['update'] === 1 || $cfg['update'] === 'on' ? 'json/update/' . $cfg['url'] : $cfg['update']);
                 }
                 if (isset($cfg['delete'])) {
                     $this->set_delete($cfg['delete'] === 1 || $cfg['delete'] === 'on' ? 'json/delete/' . $cfg['url'] : $cfg['delete']);
                 }
             }
             $this->dataSource->transport($this->transport);
         }
         if (isset($cfg['data'])) {
             $this->dataSource->data($cfg['data']);
         }
         $this->schema->model($this->model);
         $this->dataSource->schema($this->schema)->pageSize(50);
         $this->grid->attr("class", "appui-full-height")->datasource($this->dataSource)->editable(['mode' => 'popup'])->filterable(true)->resizable(true)->sortable(true)->groupable(true)->pageable(true)->columnMenu(true)->edit(new \Kendo\JavaScriptFunction('function(){
             $(".k-edit-form-container").parent().css({
               height:"auto",
               width:720,
               "max-height":appui.v.height-100
             }).restyle().data("kendoWindow").title("' . \bbn\str\text::escape_dquotes($cfg['description']) . '").center();
            }'));
         $this->cfg['args'] = [$this->id];
         $this->cfg['datasource']['schema']['model']['id'] = $this->primary;
     }
 }
Ejemplo n.º 8
0
 /**
  * @return void 
  */
 public function delete_db_index($table, $column)
 {
     if (($table = $this->table_full_name($table, 1)) && text::check_name($column)) {
         $this->db->raw_query("\n\t\t\t\tALTER TABLE {$table}\n\t\t\t\tDROP INDEX `{$column}`");
     }
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Inserts row(s) in a table.
  * 
  * <code>
  * $this->db->insert(
  *  "table_users",
  *  [
  *    ["name" => "Ted"],
  *    ["surname" => "McLow"]
  *  ]);
  * </code>
  * 
  * @param string $table The table name.
  * @param array $values The values to insert.
  * @param bool $ignore If true, controls if the row is already existing and ignores it.
  * 
  * @return int Number affected rows.
  */
 public function insert($table, array $values, $ignore = false)
 {
     $r = false;
     $trig = 1;
     $keys = array_keys($values);
     if (isset($keys[0]) && $keys[0] === 0) {
         $keys = array_keys($values[0]);
     } else {
         $values = [$values];
     }
     $affected = 0;
     if ($sql = $this->_statement('insert', $table, $keys, $ignore)) {
         foreach ($values as $i => $vals) {
             if ($this->triggers_disabled) {
                 if ($r = $this->query($sql['sql'], $sql['hash'], array_values($vals))) {
                     $affected += $r;
                 }
             } else {
                 // in case the trigger is called, values might be changed by the callback.
                 // In this case, they will be sent back in the result array as 'values'
                 // Then  the SQL statement needs to be rebuilt
                 $trig = $this->_trigger($table, 'insert', 'before', $vals);
                 if (!is_array($trig)) {
                     $trig = ['trig' => $trig];
                 }
                 if ($trig['trig']) {
                     if (isset($trig['values'])) {
                         $vals = $trig['values'];
                         if (!($sql = $this->_statement('insert', $table, array_keys($vals), $ignore))) {
                             die($this->log("Problem with the values returned by the callback function(s)", $table, $vals));
                         }
                     }
                     if ($r = $this->query($sql['sql'], $sql['hash'], array_values($vals))) {
                         $affected += $r;
                         $this->_trigger($table, 'insert', 'after', $vals);
                     }
                     if (isset($trig['value'])) {
                         if (\bbn\str\text::is_integer($trig['value'])) {
                             $affected += $trig['value'];
                         } else {
                             $affected = $trig['value'];
                         }
                     }
                 }
             }
         }
     }
     return $affected;
 }
Ejemplo n.º 10
0
 /**
  * @return void 
  */
 public function listFiles($path = '.')
 {
     $res = [];
     if ($this->cn && @ftp_chdir($this->cn, $path) && ($files = ftp_nlist($this->cn, $path))) {
         foreach ($files as $file) {
             $ele = ['name' => $file, 'basename' => basename($file)];
             if (@ftp_chdir($this->cn, $path . '/' . $ele['basename'])) {
                 $num = ftp_nlist($this->cn, '.');
                 $ele['num'] = count($num);
                 $ele['type'] = 'dir';
                 @ftp_cdup($this->cn);
             } else {
                 $ele['type'] = \bbn\str\text::file_ext($file);
             }
             array_push($res, $ele);
         }
         return $res;
     }
     return false;
 }
Ejemplo n.º 11
0
 public function ele_and_script()
 {
     return ['$(\'' . \bbn\str\text::escape_squotes($this->html()) . '\')', $this->script(false)];
 }
Ejemplo n.º 12
0
 public function label($cfg)
 {
     if (isset($cfg['null']) && $cfg['null']) {
         $label = ['tag' => 'div', 'attr' => ['class' => self::$label_class], 'content' => []];
         $tmp = ['tag' => 'label', 'text' => isset($cfg['label']) ? $cfg['label'] : ' '];
         if (isset($cfg['attr']['id'])) {
             $tmp['attr'] = ['for' => $cfg['attr']['id']];
         }
         array_push($label['content'], $tmp);
         $label_content = ['tag' => 'div', 'css' => ['display' => 'block', 'position' => 'absolute', 'right' => '0px', 'top' => '3px'], 'content' => [['tag' => 'span', 'text' => 'Null?  '], ['tag' => 'input', 'attr' => ['id' => \bbn\str\text::genpwd(), 'type' => 'checkbox'], 'events' => ['click' => 'function(e){
                     $("#' . $cfg['attr']['id'] . '").prop("disabled", $(this).is(":checked"));' . (isset($cfg['widget']['name']) ? '
                     appui.f.log("' . $cfg['widget']['name'] . '");
                     try{
                       $("#' . $cfg['attr']['id'] . '").' . $cfg['widget']['name'] . '("enable", (!$(this).is(":checked")));
                     }
                     catch(err){
                       appui.f.log(err);
                     }' : '') . '
                   }']]]];
         if (empty($cfg['attr']['value'])) {
             $label_content['content'][1]['attr']['checked'] = true;
         }
         array_push($label['content'], $label_content);
     } else {
         $label = ['tag' => 'label', 'text' => isset($cfg['label']) ? $cfg['label'] : ' ', 'attr' => ['class' => self::$label_class]];
         if (isset($cfg['attr']['id'])) {
             $label['attr']['for'] = $cfg['attr']['id'];
         }
     }
     return new \bbn\html\element($label);
 }
Ejemplo n.º 13
0
 /**
  * Creates a new user and returns its configuration (with the new ID)
  * 
  * @param array $cfg A configuration array
  * @return array 
  */
 public function edit($cfg, $id_user = false)
 {
     $fields = array_unique(array_merge(array_values($this->cfg['arch']['users']), $this->cfg['additional_fields']));
     $cfg[$this->cfg['arch']['users']['status']] = 1;
     foreach ($cfg as $k => $v) {
         if (!in_array($k, $fields)) {
             unset($cfg[$k]);
         }
     }
     if (!$id_user && isset($cfg[$this->cfg['arch']['users']['id']])) {
         $id_user = $cfg[$this->cfg['arch']['users']['id']];
         unset($cfg[$this->cfg['arch']['users']['id']]);
     }
     if ($id_user && (!isset($cfg[$this->cfg['arch']['users']['email']]) || \bbn\str\text::is_email($cfg[$this->cfg['arch']['users']['email']]))) {
         $this->db->update($this->cfg['tables']['users'], $cfg, [$this->cfg['arch']['users']['id'] => $id_user]);
         return $cfg;
     }
     return false;
 }
Ejemplo n.º 14
0
 public function get_users($user = '', $host = '')
 {
     $cond = '';
     if (!empty($user) && \bbn\str\text::check_name($user)) {
         $cond .= " AND  user LIKE '{$user}' ";
     }
     if (!empty($host) && \bbn\str\text::check_name($host)) {
         $cond .= " AND  host LIKE '{$host}' ";
     }
     $us = $this->db->get_rows("\n      SELECT DISTINCT host, user\n      FROM mysql.user\n      WHERE 1\n      {$cond}");
     $q = [];
     foreach ($us as $u) {
         $gs = $this->db->get_col_array("SHOW GRANTS FOR '{$u['user']}'@'{$u['host']}'");
         foreach ($gs as $g) {
             array_push($q, $g);
         }
     }
     return $q;
 }
Ejemplo n.º 15
0
 function tree($path, $ver_path, $c = false, $ext = false)
 {
     $res = [];
     foreach (\bbn\file\dir::get_files($path, 1) as $p) {
         if (empty($ext) || !empty($ext) && (\bbn\str\text::file_ext($p) === $ext || \bbn\str\text::file_ext($p) === '')) {
             $pa = substr($p, strlen($ver_path), strlen($p));
             $r = ['text' => basename($p), 'path' => strpos($pa, '/') === 0 ? substr($pa, 1, strlen($pa)) : $pa];
             if (!empty($c) && in_array($r['path'], $c)) {
                 $r['checked'] = 1;
             }
             if (is_dir($p)) {
                 $r['items'] = tree($p, $ver_path, $c, $ext);
             }
             if (!is_dir($p) || is_dir($p) && !empty($r['items'])) {
                 array_push($res, $r);
             }
         }
     }
     return $res;
 }
Ejemplo n.º 16
0
 /**
  * Moves a file or directory to a new location
  * 
  * <code>
  * \bbn\file\dir::move("C:\Documents\Test\Old", "C:\Documents\Test\New");
  * </code>
  * 
  * @param string $orig The file to be moved
  * @param string $dest The full name of the destination (including basename)
  * @param mixed $st If $st === true it will be copied over if the destination already exists, otherwise $st will be used to rename the new file in case of conflict
  * @param int $length The number of characters to use for the revision number; will be zerofilled
  * 
  * @return string the (new or not) name of the destination or false
  */
 public static function move($orig, $dest, $st = '_v', $length = 0)
 {
     if (file_exists($orig) && self::create_path(dirname($dest))) {
         if (file_exists($dest)) {
             if ($st === true) {
                 self::delete($dest);
             } else {
                 $i = 1;
                 while ($i) {
                     $dir = dirname($dest) . '/';
                     $file_name = \bbn\str\text::file_ext($dest, 1);
                     $file = $file_name[0] . $st;
                     if ($length > 0) {
                         $len = strlen(\bbn\str\text::cast($i));
                         if ($len > $length) {
                             return false;
                         }
                         $file .= str_repeat('0', $length - $len);
                     }
                     $file .= \bbn\str\text::cast($i);
                     if (!empty($file_name[1])) {
                         $file .= '.' . $file_name[1];
                     }
                     $i++;
                     if (!file_exists($dir . $file)) {
                         $dest = $dir . $file;
                         $i = false;
                     }
                 }
             }
         }
         if (rename($orig, $dest)) {
             return basename($dest);
         }
     }
     return false;
 }
Ejemplo n.º 17
0
 /**
  * Returns the element with its label and inside a div
  * 
  * @return string
  */
 public function html_with_label($with_script = 1)
 {
     $s = $this->html();
     if (!empty($s)) {
         if (BBN_IS_DEV) {
             $title = str_replace('"', '', print_r(\bbn\str\text::make_readable($this->cfg), true));
         } else {
             if (isset($this->attr['title'])) {
                 $title = $this->attr['title'];
             } else {
                 $title = isset($this->label) ? $this->label : '';
             }
         }
         if (!isset($this->cfg['field']) || $this->cfg['field'] !== 'hidden') {
             $s = '<label class="appui-form-label" title="' . $title . '" for="' . $this->attr['id'] . '">' . $this->label . '</label><div class="appui-form-field">' . $s . '</div>';
         }
     }
     return $s;
 }
Ejemplo n.º 18
0
 public function get_next_date($frequency, $timestamp = false)
 {
     if (is_string($frequency) && strlen($frequency) >= 2) {
         if (!$timestamp) {
             $timestamp = time();
         }
         $letter = \bbn\str\text::change_case(substr($frequency, 0, 1), 'lower');
         $number = (int) substr($frequency, 1);
         if ($number > 0) {
             switch ($letter) {
                 case 'i':
                     $unit = 60;
                     break;
                 case 'h':
                     $unit = 3600;
                     break;
                 case 'd':
                     $unit = 24 * 3600;
                     break;
                 case 'w':
                     $unit = 7 * 24 * 3600;
                     break;
             }
             if (isset($unit)) {
                 $r = $timestamp + $unit * $number;
             }
             if ($letter === 'm') {
                 $r = mktime(date('H', $timestamp), date('i', $timestamp), date('s', $timestamp), date('n', $timestamp) + $number, date('j', $timestamp), date('Y', $timestamp));
             }
             if ($letter === 'y') {
                 $r = mktime(date('H', $timestamp), date('i', $timestamp), date('s', $timestamp), date('n', $timestamp) + $number, date('j', $timestamp), date('Y', $timestamp));
             }
             if (isset($r)) {
                 if ($r < time()) {
                     return $this->get_next_date($frequency, $r);
                 }
                 return $r;
             }
         }
     }
     return false;
 }
Ejemplo n.º 19
0
 public static function get_row_back($table, array $columns, array $where, $when)
 {
     if (!is_int($when)) {
         $when = strtotime($when);
     }
     $when = (int) $when;
     if (\bbn\str\text::check_name($table) && $when > 0 && count($where) === 1) {
         $when = date('Y-m-d H:i:s', $when);
         if (count($columns) === 0) {
             $columns = array_keys(self::$db->get_columns($table));
         }
         foreach ($columns as $col) {
             $fc = self::$db->current . '.' . self::$db->col_full_name($col, $table);
             if (!($r[$col] = self::$db->get_one("\n          SELECT old\n          FROM bbn_history\n          WHERE `column` LIKE ?\n          AND `line` = ?\n          AND ( `operation` LIKE 'UPDATE' OR `operation` LIKE 'DELETE')\n          AND last_mod >= ?\n          ORDER BY last_mod ASC", $fc, end($where), $when))) {
                 $r[$col] = self::$db->get_val($table, $col, $where);
             }
         }
         return $r;
     }
     return false;
 }
Ejemplo n.º 20
0
 /**
  * Returns a variable in a fashion that is directly usable by PHP.
  * 
  * @param mixed $o The item to be.
  * @param bool $remove_empty Default: "false".
  * @param int $lev Default: "1".
  * 
  * @return mixed
  */
 public static function export($o, $remove_empty = false, $lev = 1)
 {
     $st = '';
     if (is_object($o) && ($cls = get_class($o)) && $cls !== 'stdClass') {
         $st .= "Object " . get_class($o) . PHP_EOL;
     }
     if (is_object($o) || is_array($o)) {
         $is_assoc = is_object($o) || \bbn\tools::is_assoc($o);
         $st .= $is_assoc ? '{' : '[';
         $st .= PHP_EOL;
         foreach ($o as $k => $v) {
             if ($remove_empty && (is_string($v) && empty($v) || is_array($v) && count($v) === 0)) {
                 continue;
             }
             $st .= str_repeat('    ', $lev);
             if ($is_assoc) {
                 $st .= (is_string($k) ? "'" . \bbn\str\text::escape_squote($k) . "'" : $k) . ": ";
             }
             if (is_array($v)) {
                 $st .= self::export($v, $remove_empty, $lev + 1);
             } else {
                 if (is_object($v)) {
                     $cls = get_class($v);
                     if ($cls === 'stdClass') {
                         $st .= self::export($v, $remove_empty, $lev + 1);
                     } else {
                         $st .= "Object {$cls}";
                     }
                 } else {
                     if ($v === 0) {
                         $st .= '0';
                     } else {
                         if (is_null($v)) {
                             $st .= 'null';
                         } else {
                             if (is_bool($v)) {
                                 $st .= $v === false ? 'false' : 'true';
                             } else {
                                 if (is_int($v) || is_float($v)) {
                                     $st .= $v;
                                 } else {
                                     if (!$remove_empty || !empty($v)) {
                                         $st .= "'" . \bbn\str\text::escape_squote($v) . "'";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $st .= ',' . PHP_EOL;
         }
         $st .= str_repeat('    ', $lev - 1);
         $st .= $is_assoc ? '}' : ']';
         return $st;
     }
     return $o;
 }
Ejemplo n.º 21
0
 /**
  * This will fetch the route to the controller for a given path. Chainable
  *
  * @param string $path The request path <em>(e.g books/466565 or xml/books/48465)</em>
  * @return void 
  */
 private function route($path = '')
 {
     if (!$this->is_routed && self::check_path($path)) {
         $this->is_routed = 1;
         $this->path = $path;
         $fpath = $path;
         // We go through each path, starting by the longest until it's empty
         while (strlen($fpath) > 0) {
             if ($this->get_controller($fpath)) {
                 if (strlen($fpath) < strlen($this->path)) {
                     $this->arguments = [];
                     $args = explode('/', substr($this->path, strlen($fpath)));
                     foreach ($args as $a) {
                         if (\bbn\str\text::is_number($a)) {
                             $a = (int) $a;
                         }
                         array_push($this->arguments, $a);
                     }
                     // Trimming the array
                     while (empty($this->arguments[0])) {
                         array_shift($this->arguments);
                     }
                     $t = end($this->arguments);
                     while (empty($t)) {
                         array_pop($this->arguments);
                         $t = end($this->arguments);
                     }
                 }
                 break;
             } else {
                 $fpath = strpos($fpath, '/') === false ? '' : substr($this->path, 0, strrpos($fpath, '/'));
             }
         }
         if (!$this->controller) {
             $this->get_controller('default');
         }
     }
     return $this;
 }
Ejemplo n.º 22
0
 /**
  * 
  * 
  */
 public static function sort(&$ar)
 {
     usort($ar, function ($a, $b) {
         $a = str_replace('.', '0', str_replace('_', '1', \bbn\str\text::change_case($a, 'lower')));
         $b = str_replace('.', '0', str_replace('_', '1', \bbn\str\text::change_case($b, 'lower')));
         return strcmp($a, $b);
     });
 }
Ejemplo n.º 23
0
 /**
  * @return string
  */
 public static function make_fingerprint()
 {
     return \bbn\str\text::genpwd(32, 16);
 }
Ejemplo n.º 24
0
 /**
  * @return void 
  */
 public function fetchObject($class_name = "stdClass", $ctor_args = array())
 {
     $this->execute();
     return \bbn\str\text::correct_types(parent::fetchObject($class_name, $ctor_args));
 }
Ejemplo n.º 25
0
 /**
  * Empties the structure tables for a given database and refill them with the current structure
  * 
  * @param string $db
  * @return void
  */
 public function update($db = '')
 {
     apc_clear_cache();
     apc_clear_cache("user");
     if (empty($db)) {
         $db = $this->db->current;
     }
     if (\bbn\str\text::check_name($db)) {
         $change = $this->db->current === $db ? false : $this->db->current;
         if ($change) {
             $this->db->change($db);
         }
         $schema = $this->db->modelize();
         if ($change) {
             $this->db->change($change);
         }
         /*
         $projects = [];
         $r1 = $this->db->query("SELECT *
         FROM `{$this->admin_db}`.`{$this->prefix}projects`
         WHERE `db` LIKE '$db'");
         while ( $d1 = $r1->get_row() ){
         	$projects[$d1['id']] = $d1;
         	$projects[$d1['id']]['forms'] = [];
         	$r2 = $this->db->query("
         		SELECT id
         		FROM `{$this->admin_db}`.`{$this->prefix}forms`
         		WHERE `id_project` = ?",
         		$d1['id']);
         	while ( $d2 = $r2->get_row() ){
         		$projects[$d1['id']]['forms'][$d2['id']] = $this->get_form_config();
         	}
         }
         */
         $this->db->query("DELETE IGNORE FROM `{$this->prefix}dbs` WHERE id LIKE '{$db}.%'");
         $this->db->query("DELETE IGNORE FROM `{$this->prefix}tables` WHERE id LIKE '{$db}.%'");
         $this->db->query("DELETE IGNORE FROM `{$this->prefix}columns` WHERE id LIKE '{$db}.%'");
         $this->db->query("DELETE IGNORE FROM `{$this->prefix}keys` WHERE id LIKE '{$db}.%'");
         $this->db->raw_query("\n        INSERT IGNORE INTO `{$this->admin_db}`.`{$this->prefix}dbs`\n        (`id`, `host`, `db`)\n        VALUES\n        ('{$db}', '{$this->db->host}', '{$db}')");
         $has_history = false;
         if (\bbn\appui\history::$is_used && isset($schema[\bbn\appui\history::$htable])) {
             $has_history = 1;
         }
         foreach ($schema as $t => $vars) {
             if (strpos($t, '.' . $this->prefix) === false) {
                 $tmp = explode(".", $t);
                 $db = $tmp[0];
                 $table = $tmp[1];
                 $this->db->insert_update($this->admin_db . '.' . $this->prefix . 'tables', ['id' => $t, 'db' => $db, 'table' => $table]);
                 foreach ($vars['fields'] as $col => $f) {
                     $config = new \stdClass();
                     if ($has_history && array_key_exists(\bbn\appui\history::$hcol, $vars['fields']) && $col !== \bbn\appui\history::$hcol) {
                         $config->history = 1;
                     }
                     if (isset($f['default'])) {
                         $config->default = $f['default'];
                     }
                     if (!empty($f['extra'])) {
                         $config->extra = $f['extra'];
                     }
                     if (isset($f['signed']) && $f['signed'] == 1) {
                         $config->signed = 1;
                     }
                     if (isset($f['null']) && $f['null'] == '1') {
                         $config->null = 1;
                     }
                     if (isset($f['maxlength']) && $f['maxlength'] > 0) {
                         $config->maxlength = (int) $f['maxlength'];
                     }
                     if (isset($f['keys'])) {
                         $config->keys = [];
                         foreach ($f['keys'] as $key) {
                             $config->keys[$key] = $vars['keys'][$key];
                         }
                     }
                     $this->db->insert_update($this->admin_db . '.' . $this->prefix . 'columns', ['id' => $t . '.' . $col, 'table' => $t, 'column' => $col, 'position' => $f['position'], 'type' => $f['type'], 'null' => $f['null'], 'key' => $f['key'], 'config' => json_encode($config)]);
                 }
             }
         }
         foreach ($schema as $t => $vars) {
             if (strpos($t, '.' . $this->prefix) === false) {
                 if (is_array($vars['keys'])) {
                     foreach ($vars['keys'] as $k => $arr) {
                         $pos = 1;
                         foreach ($arr['columns'] as $c) {
                             $this->db->insert_update($this->admin_db . '.' . $this->prefix . 'keys', ['id' => $t . '.' . $c . '.' . $k, 'key' => $k, 'column' => $t . '.' . $c, 'position' => $pos, 'ref_column' => is_null($arr['ref_column']) ? null : $arr['ref_db'] . '.' . $arr['ref_table'] . '.' . $arr['ref_column']]);
                             $pos++;
                         }
                     }
                 } else {
                     \bbn\tools::log($t);
                     \bbn\tools::log($vars['keys']);
                 }
             }
         }
         /*
         			foreach ( $projects as $i => $p ){
         				$this->db->insert($this->admin_db.'.'.$this->prefix.'projects',[
         					'id' => $i,
         					'id_client' => $p['id_client'],
         					'db' => $p['db'],
         					'name' => $p['name'],
         					'config' => $p['config']]);
         				foreach ( $p['forms'] as $j => $form ){
         					$this->db->insert($this->admin_db.'.'.$this->prefix.'forms',[
         						'id' => $j,
         						'id_project' => $i
         					]);
         					foreach ( $form as $field ){
         						$this->db->insert_ignore($this->admin_db.'.'.$this->prefix.'fields',[
         							'id' => $field['id'],
         							'id_form' => $j,
         							'column' => $field['column'],
         							'title' => $field['title'],
         							'position' => $field['position'],
         							'configuration' => json_encode($field['configuration'])
         						]);
         					}
         				}
         			}
         * 
         */
     }
 }
Ejemplo n.º 26
0
 public function filter($filters)
 {
     $res = '';
     if ($this->check() && isset($filters['filters'])) {
         if (isset($filters['filters']) && count($filters['filters']) > 0) {
             $logic = isset($filters['logic']) && $filters['logic'] === 'or' ? 'OR' : 'AND';
             foreach ($filters['filters'] as $f) {
                 $ok = false;
                 if (empty($res)) {
                     $pre = " ( ";
                 } else {
                     $pre = " {$logic} ";
                 }
                 if (isset($f['logic'])) {
                     $res .= $pre . $this->filter($f);
                 } else {
                     if ($field = $this->get_field($f)) {
                         if ($this->structure && isset($this->structure['fields'][$f['field']])) {
                             if ($this->structure['fields'][$f['field']]['type'] === 'int' && $this->structure['fields'][$f['field']]['maxlength'] == 1 && !\bbn\str\text::is_integer($f['value'])) {
                                 $f['value'] = $f['value'] === 'true' ? 1 : 0;
                             }
                         }
                         $res .= $pre . $field . " ";
                         switch ($f['operator']) {
                             case 'eq':
                                 $res .= \bbn\str\text::is_number($f['value']) ? "= " . $f['value'] : "LIKE '" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'neq':
                                 $res .= \bbn\str\text::is_number($f['value']) ? "!= " . $f['value'] : "NOT LIKE '" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'startswith':
                                 $res .= "LIKE '" . $this->db->escape_value($f['value']) . "%'";
                                 break;
                             case 'endswith':
                                 $res .= "LIKE '%" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'gte':
                                 $res .= ">= '" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'gt':
                                 $res .= "> '" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'lte':
                                 $res .= "<= '" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'lt':
                                 $res .= "< '" . $this->db->escape_value($f['value']) . "'";
                                 break;
                             case 'contains':
                             default:
                                 $res .= "LIKE '%" . $this->db->escape_value($f['value']) . "%'";
                                 break;
                             case 'doesnotcontain':
                                 $res .= "NOT LIKE ? ";
                                 $f['value'] = '%' . $f['value'] . '%';
                                 break;
                         }
                     }
                 }
             }
             if (!empty($res)) {
                 $res .= " ) ";
             }
         }
     }
     return $res;
 }