Example #1
0
 function handle_event($event)
 {
     global $sql;
     if ($event->rem_name == 'submit') {
         $r = unserialize($_POST['val']);
         //print 'alert(\''.js_escape(serialize($r[1][0]['ok'])).'\');';
         //print 'alert(\''.js_escape(serialize($t)).'\');';
         for ($y = 1; $y <= keyboard_test::TEST_NUM; $y++) {
             $q = new query_gen_ext('INSERT UPDATE');
             $q->into->exprs[] = new sql_column(NULL, 'keyboard_test');
             $q->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'user-agent'), new sql_immed($_SERVER['HTTP_USER_AGENT'])));
             $q->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'testn'), new sql_immed($y)));
             $q->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'keypress-result'), new sql_immed($r[$y][0]['ok'] == 1 ? $r[$y][0]['cnt'] . '/' . $r[$y][0]['kc'] . '/' . $r[$y][0]['cc'] . '/' . $r[$y][0]['wh'] : 'n')));
             $q->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'keydown-result'), new sql_immed($r[$y][1]['ok'] == 1 ? $r[$y][1]['cnt'] . '/' . $r[$y][1]['kc'] . '/' . $r[$y][1]['cc'] . '/' . $r[$y][1]['wh'] : 'n')));
             $q->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'keyup-result'), new sql_immed($r[$y][2]['ok'] == 1 ? $r[$y][2]['cnt'] . '/' . $r[$y][2]['kc'] . '/' . $r[$y][2]['cc'] . '/' . $r[$y][2]['wh'] : 'n')));
             $sql->query($q->result());
         }
     }
     editor_generic::handle_event($event);
 }
Example #2
0
 function parse($l)
 {
     global $sql;
     $le = explode("\n", $l);
     $im_code = new sql_immed();
     $im_count = new sql_immed(1);
     $im_place = new sql_immed();
     $im_zone = new sql_immed();
     $sq = new query_gen_ext('select');
     $sq->from->exprs[] = new sql_column(NULL, 'barcodes_raw', NULL, 'br');
     $sq->what->exprs[] = new sql_column(NULL, 'br', 'id');
     $sq->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'br', 'code'), $im_code));
     $qg = new query_gen_ext('insert update');
     $qg->into->exprs[] = new sql_column(NULL, 'test_doc', NULL);
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'doc_id'), new sql_immed($this->args['id_doc'])));
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'prod'), new sql_subquery($sq)));
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'place'), $im_place));
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'zone'), $im_zone));
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'count'), $im_count));
     $qg->update->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, 'count'), new sql_expression('+', array(new sql_column(NULL, NULL, 'count'), $im_count))));
     $mm = array();
     $im_place->val = 1;
     $place = 0;
     $zone = 1;
     foreach ($le as $r) {
         if (preg_match('/^[0-9]{13}$/', $r)) {
             //				print "alert('".js_escape($qg->result())."');";
             if (isset($mm[$zone][$place][$r])) {
                 $mm[$zone][$place][$r] += 1;
             } else {
                 $mm[$zone][$place][$r] = 1;
             }
         }
         if (preg_match('/^0[1-9]$/i', $r) || preg_match('/^X[0-9]$/i', $r)) {
             $place -= $place % 10;
             $place += intval($r[1]);
         }
         if (preg_match('/^A[0-9]$/i', $r)) {
             $zone = intval($r[1]);
         }
         if (preg_match('/^[0-9]$/', $r)) {
             $zone = intval($r[0]);
         }
         if (preg_match('/^[1-9]0$/i', $r) || preg_match('/^[0-9]X$/i', $r)) {
             $place = $place % 10;
             $place += intval($r[0]) * 10;
         }
         if (preg_match('/^00$/', $r)) {
             $place = 0;
         }
     }
     foreach ($mm as $zone => $xx) {
         foreach ($xx as $place => $u) {
             foreach ($u as $code => $count) {
                 $im_zone->val = $zone;
                 $im_place->val = $place;
                 $im_code->val = $code;
                 $im_count->val = $count;
                 $sql->query($qg->result());
             }
         }
     }
 }
Example #3
0
 function html_inner()
 {
     global $sql;
     $r = $sql->fetch1($sql->query("SELECT count(1) FROM `" . TABLE_META_TREE_TMP . "`"));
     if ($r > 0) {
         $t = TABLE_META_TREE_TMP;
         $ins = new query_gen_ext('INSERT UPDATE');
         $ins->into->exprs[] = new sql_column(NULL, $t);
         unset($ins_vars);
     } else {
         $t = TABLE_META_TREE;
     }
     $new = new ddc_key();
     $new->attach(TABLE_META_TREE_TMP, $sql);
     $diff = $new->inheritance_update();
     if (is_array($diff)) {
         $this->tbl->html_head();
     }
     if (is_array($diff)) {
         foreach ($diff as $d) {
             $this->args['type'] = $d->type;
             $this->args['id'] = $d->id;
             $this->args['href'] = '';
             $this->args['name'] = $d->descr;
             $this->args['change'] = "";
             $this->args['apply'] = "apply";
             foreach ($d->row as $rk => $rv) {
                 $this->args['change'] .= $rk . "=" . $rv . ";";
                 if (isset($ins) && $d->type == '+') {
                     if (isset($ins_vars[$rk])) {
                         $ins_vars[$rk]->value = $rv;
                     } else {
                         $ins_vars[$rk] = new sql_immed($rv);
                         $ins->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, $rk), $ins_vars[$rk]));
                     }
                 }
             }
             if (isset($ins) && $d->type == '+') {
                 $this->args['apply'] = $ins->result();
             } else {
                 $this->args['apply'] = "";
             }
             if (isset($ins) && ($d->type == '*q' || $d->type == '-q' || $d->type == '+q')) {
                 $this->args['apply'] = $d->row['query'];
             }
             //$this->args['meta_change']=$d->meta_change;
             //$this->args['change']=count($d->diff);
             $this->row->css_style['background'] = '';
             switch ($d->type) {
                 case '-':
                     $this->row->css_style['background'] = string_to_color('sql_table', 2);
                     break;
                 case '+':
                     $this->row->css_style['background'] = string_to_color('name', 2);
                     break;
                 case '*':
                     $this->row->css_style['background'] = 'yellow';
                     break;
             }
             $this->row->html();
             $this->row->id_alloc();
         }
     } else {
         $this->gen_error->text = $diff;
         $this->gen_error->html();
     }
     if (is_array($diff)) {
         $this->tbl->html_tail();
     }
 }
Example #4
0
 function html_inner()
 {
     global $sql;
     unset($db);
     if ($this->args['ed_db'] != '') {
         $db = $this->args['ed_db'];
     }
     $qg = new query_gen_ext('SELECT');
     $qg->from->exprs[] = new sql_column($db, $this->args['ed_table'], NULL, 't');
     $qg->what->exprs[] = new sql_list('count', array(new sql_immed(1)));
     $q = $qg->result();
     if (isset($q)) {
         $res = $sql->query($q);
         if ($res) {
             $this->txt->text = $sql->fetch1($res);
         } else {
             $this->txt->text = $sql->err();
         }
     } else {
         $this->txt->text = "error";
     }
     parent::html_inner();
 }
Example #5
0
 function inheritance_update($show = true)
 {
     //table level
     //find columns that differ from parents - update
     global $ddc_key_special_types;
     $synclist = array('name', 'sql_type', 'sql_null', 'sql_sequence', 'sql_default', 'sql_comment', 'sql_keyname', 'sql_keylen');
     $qt = new query_gen_ext('UPDATE');
     $qt->into->exprs[] = new sql_column(NULL, $this->tree, NULL, 'a');
     $qt->into->exprs[] = new sql_column(NULL, $this->tree, NULL, 'b');
     $qt->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'a', 'inheritedfrom'), new sql_column(NULL, 'b', 'id')));
     $dl = new sql_expression('OR');
     foreach ($synclist as $li) {
         $dl->exprs[] = new sql_expression('!=', array(new sql_column(NULL, 'a', $li), new sql_column(NULL, 'b', $li)));
         $qt->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'a', $li), new sql_column(NULL, 'b', $li)));
         $qt->what->exprs[] = new sql_column(NULL, 'b', $li, $li);
     }
     $qt->where->exprs[] = $dl;
     $restypes = new sql_list('IN');
     foreach ($ddc_key_special_types as $t) {
         $restypes->exprs[] = new sql_immed($t);
     }
     $qt->where->exprs[] = new sql_expression('NOT', array(new sql_column(NULL, 'a', 'sql_type'), $restypes));
     //exec query
     $inh_update = $qt;
     $inh_update_v = new query_gen_ext("select");
     $inh_update_v->from = $qt->into;
     $inh_update_v->what = $qt->what;
     $inh_update_v->what->exprs[] = new sql_column(NULL, 'a', 'id', 'id');
     $inh_update_v->what->exprs[] = new sql_column(NULL, 'b', 'id', 'inheritedfrom');
     $inh_update_v->where = $qt->where;
     if (!$show) {
         $res = $this->sql->query($inh_update->result());
     } else {
         $r->type = "*q";
         $r->row = array("query" => $inh_update->result());
         $ret[] = $r;
         unset($r);
         $res = $this->sql->query($inh_update_v->result());
         while ($row = $this->sql->fetcha($res)) {
             $r->type = '*';
             $r->row = $row;
             $ret[] = $r;
             unset($r);
         }
     }
     //find lost columns - delete
     $qt = new query_gen_ext('DELETE');
     $qt->what->exprs[] = new sql_column(NULL, 'a');
     $qt->from->exprs[] = new sql_column(NULL, $this->tree, NULL, 'a');
     $join->what = new sql_column(NULL, $this->tree, NULL, 'b');
     $join->on = new sql_expression('=', array(new sql_column(NULL, 'a', 'inheritedfrom'), new sql_column(NULL, 'b', 'id')));
     $join->type = 'left outer join';
     $qt->joins->exprs[] = $join;
     $qt->where->exprs[] = new sql_expression('IS', array(new sql_column(NULL, 'b', 'id'), new sql_null()));
     $qt->where->exprs[] = new sql_expression('IS NOT', array(new sql_column(NULL, 'a', 'inheritedfrom'), new sql_null()));
     $qt->where->exprs[] = new sql_expression('!=', array(new sql_column(NULL, 'a', 'inheritedfrom'), new sql_immed(0)));
     //exec query while result is true
     $inh_delete = $qt;
     $inh_delete_v = new query_gen_ext("select");
     $inh_delete_v->from = $qt->from;
     $inh_delete_v->joins = $qt->joins;
     $inh_delete_v->where = $qt->where;
     $inh_delete_v->what->exprs[] = new sql_column(NULL, 'a', 'id', 'id');
     $inh_delete_v->what->exprs[] = new sql_column(NULL, 'a', 'id', 'inheritedfrom');
     if (!$show) {
         $res &= $this->sql->query($inh_delete->result());
     } else {
         $r->type = "-q";
         $r->row = array("query" => $inh_delete->result());
         $ret[] = $r;
         unset($r);
         $res = $this->sql->query($inh_delete_v->result());
         while ($row = $this->sql->fetcha($res)) {
             $r->type = '-';
             $r->row = $row;
             $ret[] = $r;
             unset($r);
         }
     }
     //find new columns (parent has, child does not) - add as shared to all objects having columns from that table
     $qt = new query_gen_ext('SELECT');
     $qt->from->exprs[] = new sql_column(NULL, $this->tree, NULL, 'tp');
     $qt->from->exprs[] = new sql_column(NULL, $this->tree, NULL, 'tc');
     $qt->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'tp', 'id'), new sql_column(NULL, 'tc', 'inheritedfrom')));
     $qt->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'tp', 'sql_type'), new sql_immed('table')));
     $qt->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'tc', 'sql_type'), new sql_immed('table')));
     $qt->from->exprs[] = new sql_column(NULL, $this->tree, NULL, 'cp');
     $qt->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'tp', 'sql_table'), new sql_column(NULL, 'cp', 'sql_table')));
     $qt->where->exprs[] = new sql_expression('NOT', array(new sql_column(NULL, 'cp', 'sql_type'), $restypes));
     //fetch objects
     unset($join);
     $join->what = new sql_column(NULL, $this->tree, NULL, 'ob');
     $join->on = new sql_expression('AND', array(new sql_expression('=', array(new sql_column(NULL, 'tc', 'sql_table'), new sql_column(NULL, 'ob', 'sql_table'))), new sql_expression('NOT', array(new sql_column(NULL, 'ob', 'sql_type'), clone $restypes))));
     $join->type = 'join';
     $qt->joins->exprs[] = $join;
     //fetch parent columns, not found in child table
     unset($join);
     $join->what = new sql_column(NULL, $this->tree, NULL, 'cc');
     $join->on = new sql_expression('AND', array(new sql_expression('=', array(new sql_column(NULL, 'cc', 'inheritedfrom'), new sql_column(NULL, 'cp', 'id'))), new sql_expression('=', array(new sql_column(NULL, 'cc', 'parentid'), new sql_column(NULL, 'ob', 'parentid')))));
     $join->type = 'left outer join';
     $qt->joins->exprs[] = $join;
     $qt->where->exprs[] = new sql_expression('IS', array(new sql_column(NULL, 'cc', 'id'), new sql_null()));
     foreach ($synclist as $li) {
         $qt->what->exprs[] = new sql_column(NULL, 'cp', $li, $li);
         $qt->group->exprs[] = new sql_column(NULL, 'cp', $li);
     }
     $qt->what->exprs[] = new sql_column(NULL, 'cp', 'isstored', 'isstored');
     $qt->group->exprs[] = new sql_column(NULL, 'cp', 'isstored');
     $qt->what->exprs[] = new sql_immed(1, 'isshared');
     $qt->what->exprs[] = new sql_column(NULL, 'ob', 'sql_table', 'sql_table');
     $qt->group->exprs[] = new sql_column(NULL, 'ob', 'sql_table');
     //fetch objects that have columns with sql_table==tc.sql_table
     $qt->what->exprs[] = new sql_column(NULL, 'cp', 'id', 'inheritedfrom');
     //$qt->what->exprs
     $qt->what->exprs[] = new sql_column(NULL, 'ob', 'parentid', 'parentid');
     $qt->group->exprs[] = new sql_column(NULL, 'ob', 'parentid');
     $setq = new query_gen_ext("insert select");
     $setq->into->exprs[] = new sql_column(NULL, $this->tree);
     $setq->select = $qt;
     if (!$show) {
         $res &= $this->sql->query($setq->result());
     } else {
         $r->type = "+q";
         $r->row = array("query" => $setq->result());
         $ret[] = $r;
         unset($r);
         $res = $this->sql->query($qt->result());
         while ($row = $this->sql->fetcha($res)) {
             $r->type = '+';
             $r->row = $row;
             $ret[] = $r;
             unset($r);
         }
     }
     if ($show) {
         return $ret;
     } else {
         return NULL;
     }
 }
Example #6
0
 function update_dectionary($v, $id, $search_tbl, $select, $dict)
 {
     global $sql;
     $qg = new query_gen_ext('UPDATE');
     $qg->into->exprs[] = new sql_column(NULL, $search_tbl, NULL);
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, $dict), new sql_immed('')));
     $qg->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, $dict), new sql_immed($v)));
     $sql->query($qg->result());
     unset($qg);
     $qg = new query_gen_ext('INSERT UPDATE');
     $qg->into->exprs[] = new sql_column(NULL, $search_tbl, NULL);
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, $dict), new sql_immed($v)));
     $qg->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, $select), new sql_immed($id)));
     return $sql->query($qg->result());
 }
Example #7
0
 function html_inner()
 {
     global $sql;
     $qg = new query_gen_ext('select');
     $qg->from->exprs[] = new sql_column(NULL, TABLE_META_TREE, NULL, 'mt');
     $join->type = 'LEFT OUTER JOIN';
     $join->what = new sql_column(NULL, TABLE_META_I18N, NULL, 'mi');
     $join->on = new sql_expression('AND', array(new sql_expression('=', array(new sql_column(NULL, 'mi', 'object'), new sql_column(NULL, 'mt', 'id'))), new sql_expression('=', array(new sql_column(NULL, 'mi', 'var'), new sql_immed('name'))), new sql_expression('=', array(new sql_column(NULL, 'mi', 'loc'), new sql_immed($_SESSION['lang'])))));
     $qg->joins->exprs[] = $join;
     $qg->where->exprs[] = new sql_expression('=', array(new sql_column(NULL, 'mt', 'sql_type'), new sql_immed('')));
     $qg->where->exprs[] = new sql_expression('!=', array(new sql_column(NULL, 'mt', 'xobject'), new sql_immed('sys')));
     $qg->what->exprs[] = new sql_column(NULL, 'mt', 'id');
     $qg->what->exprs[] = new sql_column(NULL, 'mt', 'name');
     $qg->what->exprs[] = new sql_list('coalesce', array(new sql_column(NULL, 'mi', 'val'), new sql_column(NULL, 'mt', 'name')), 'hr_name');
     $this->rootnode->out(htmlspecialchars($qg->result()));
     $res = $sql->query($qg->result());
     while ($row = $sql->fetcha($res)) {
         $this->href->attributes['href'] = "?p=" . $row['id'];
         $this->text->text = $row['hr_name'];
         $this->row->attributes['title'] = $row['name'];
         $this->row->css_style['background'] = string_to_color($row['name'], 2);
         $this->row->html();
     }
 }
Example #8
0
 function try_insert()
 {
     global $sql;
     $ca = $sql->qa("SHOW COLUMNS FROM `" . $sql->esc($this->edittbl) . "`");
     if (!is_array($ca)) {
         return false;
     }
     $qq = new query_gen_ext('INSERT IGNORE');
     $qq->into->exprs[] = new sql_column($this->editdb, $this->edittbl, NULL, NULL);
     foreach ($ca as $row) {
         if (isset($this->args[$row['Field']]) && $row['Key'] == 'PRI') {
             $qq->set->exprs[] = new sql_expression('=', array(new sql_column(NULL, NULL, $row['Field']), new sql_immed($this->args[$row['Field']])), NULL);
         }
     }
     /*		foreach($this->args as $i => $v)
     			$qq->set->exprs[]=
     				new sql_expression('=',
     					Array(
     						new sql_column(NULL,NULL,$i),
     						new sql_immed($v)
     					),NULL);
     */
     $q = $qq->result();
     $res = $sql->query($q);
     $ar = $sql->ar();
     //		print 'alert(\''.js_escape($q).'\');';
     return $ar > 0;
 }