Skip to content

Commit 074750e

Browse files
Merge branch 'master' of 192.168.3.251:connector-php
2 parents 8959cc7 + d5d7611 commit 074750e

17 files changed

+238
-62
lines changed

codebase/base_connector.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ class Connector {
288288
protected $encoding="utf-8";//!< assigned encoding (UTF-8 by default)
289289
protected $editing=false;//!< flag of edit mode ( response for dataprocessor )
290290

291+
public static $filter_var="dhx_filter";
292+
public static $sort_var="dhx_sort";
293+
public static $kids_var="dhx_kids";
294+
291295
public $model=false;
292296

293297
private $updating=false;//!< flag of update mode ( response for data-update )
@@ -309,7 +313,8 @@ class Connector {
309313
protected $filters;
310314
protected $sorts;
311315
protected $mix;
312-
316+
protected $order = false;
317+
313318
/*! constructor
314319
315320
Here initilization of all Masters occurs, execution timer initialized
@@ -590,22 +595,26 @@ protected function parse_request(){
590595
$this->request->set_user($_GET["dhx_user"]);
591596
}
592597

593-
if (isset($_GET["dhx_sort"]))
594-
foreach($_GET["dhx_sort"] as $k => $v){
598+
if (isset($_GET[Connector::$sort_var]))
599+
foreach($_GET[Connector::$sort_var] as $k => $v){
595600
$k = $this->safe_field_name($k);
596601
$this->request->set_sort($this->resolve_parameter($k),$v);
597602
}
598603

599-
if (isset($_GET["dhx_filter"]))
600-
foreach($_GET["dhx_filter"] as $k => $v){
604+
if (isset($_GET[Connector::$filter_var]))
605+
foreach($_GET[Connector::$filter_var] as $k => $v){
601606
$k = $this->safe_field_name($k);
602-
$this->request->set_filter($this->resolve_parameter($k),$v);
607+
if ($v !== "")
608+
$this->request->set_filter($this->resolve_parameter($k),$v);
603609
}
604610

611+
$this->check_csrf();
612+
}
613+
614+
protected function check_csrf(){
605615
$key = ConnectorSecurity::checkCSRF($this->editing);
606616
if ($key !== "")
607-
$this->add_top_attribute("dhx_security", $key);
608-
617+
$this->add_top_attribute(ConnectorSecurity::$security_var, $key);
609618
}
610619

611620
/*! convert incoming request name to the actual DB name
@@ -701,7 +710,23 @@ public function set_encoding($encoding){
701710
*/
702711
public function dynamic_loading($count){
703712
$this->dload=$count;
704-
}
713+
}
714+
715+
/*! enable or disable data reordering
716+
717+
@param name
718+
name of field, which will be used for order storing, optional
719+
by default 'sortorder' field will be used
720+
*/
721+
public function enable_order($name = true){
722+
if ($name === true)
723+
$name = "sortorder";
724+
725+
$this->sort($name);
726+
$this->access->allow("order");
727+
$this->request->set_order($name);
728+
$this->order = $name;
729+
}
705730

706731
/*! enable logging
707732
@@ -750,7 +775,10 @@ protected function xml_start(){
750775
*/
751776
protected function xml_end(){
752777
$this->fill_collections();
753-
return $this->extra_output."</data>";
778+
if (isset($this->extra_output))
779+
return $this->extra_output."</data>";
780+
else
781+
return "</data>";
754782
}
755783

756784
protected function fill_collections($list=""){

codebase/connector.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ if (window.dhtmlXGridObject && !dhtmlXGridObject.prototype._init_point_connector
8383
if (!this._colls_loaded && this.cellType){
8484
var ar=[];
8585
for (var i=0; i < this.cellType.length; i++)
86-
if (this.cellType[i].indexOf("co")==0 || this._con_f_used[i]==2) ar.push(i);
86+
if (this.cellType[i].indexOf("co")==0 || this.cellType[i].indexOf("clist")==0 || this._con_f_used[i]==2) ar.push(i);
8787
if (ar.length)
8888
arguments[0]+=(arguments[0].indexOf("?")!=-1?"&":"?")+"connector=true&dhx_colls="+ar.join(",");
8989
}
@@ -120,8 +120,13 @@ if (window.dhtmlXGridObject && !dhtmlXGridObject.prototype._init_point_connector
120120
} else
121121
v[v.length]=val;
122122
}
123-
if (opts.length)
124-
combo.addOption(opts);
123+
if (opts.length){
124+
if (combo)
125+
combo.addOption(opts);
126+
} else if (v.length && !combo)
127+
if (this.registerCList)
128+
this.registerCList(f*1, v);
129+
125130

126131
if (this._con_f_used[f*1])
127132
this._con_f_used[f*1]=v;

codebase/convert.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ private function as_file($size, $name, $inline){
4141
}
4242
public function convert($conn, $out){
4343

44+
$str_out = str_replace("<rows>","<rows profile='color'>", $out);
45+
$str_out = str_replace("<head>","<head><columns>", $str_out);
46+
$str_out = str_replace("</head>","</columns></head>", $str_out);
47+
4448
if ($this->type == "pdf")
4549
header("Content-type: application/pdf");
4650
else
@@ -50,7 +54,7 @@ public function convert($conn, $out){
5054
curl_setopt($handle, CURLOPT_POST, true);
5155
curl_setopt($handle, CURLOPT_HEADER, false);
5256
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
53-
curl_setopt($handle, CURLOPT_POSTFIELDS, "grid_xml=".urlencode(str_replace("<rows>","<rows profile='color'>", $out)));
57+
curl_setopt($handle, CURLOPT_POSTFIELDS, "grid_xml=".urlencode($str_out));
5458

5559

5660
$out->reset();

codebase/crosslink_connector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function afterProcessing($action){
109109
$this->link->delete($master_key);
110110
break;
111111
case "updated":
112+
//cross link options not loaded yet, so we can skip update
113+
if (!array_key_exists($this->link_name, $action->get_data()))
114+
break;
115+
//else, delete old options and continue in insert section to add new values
112116
$this->link->delete($master_key);
113117
case "inserted":
114118
for ($i=0; $i < sizeof($link_key); $i++)

codebase/data_connector.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ public function add_section($name, $string){
114114
}
115115

116116
protected function parse_request_mode(){
117-
//do nothing, at least for now
117+
if (isset($_GET['action']) && $_GET["action"] != "get")
118+
$this->editing = true;
119+
else
120+
parent::parse_request_mode();
118121
}
119122

120123
//parse GET scoope, all operations with incoming request must be done here
@@ -134,10 +137,10 @@ protected function parse_request(){
134137
//data saving
135138
$this->editing = true;
136139
}
140+
parent::check_csrf();
137141
} else {
138142
if (isset($_GET['editing']) && isset($_POST['ids']))
139143
$this->editing = true;
140-
141144
parent::parse_request();
142145
}
143146

@@ -149,7 +152,10 @@ protected function parse_request(){
149152
/*! renders self as xml, starting part
150153
*/
151154
protected function xml_start(){
152-
$start = parent::xml_start();
155+
$start = "<data";
156+
foreach($this->attributes as $k=>$v)
157+
$start .= " ".$k."='".$v."'";
158+
$start.= ">";
153159

154160
foreach($this->sections as $k=>$v)
155161
$start .= "<".$k.">".$v."</".$k.">\n";
@@ -195,7 +201,7 @@ protected function fill_collections($list=""){
195201
$name = $k;
196202
$option="\"{$name}\":[";
197203
if (!is_string($this->options[$name]))
198-
$option.=substr($this->options[$name]->render(),0,-2);
204+
$option.=substr(json_encode($this->options[$name]->render()),1,-1);
199205
else
200206
$option.=$this->options[$name];
201207
$option.="]";
@@ -274,8 +280,11 @@ function to_xml(){
274280
}
275281

276282
if ($this->userdata !== false)
277-
foreach ($this->userdata as $key => $value)
283+
foreach ($this->userdata as $key => $value){
284+
if ($value === null)
285+
$data[$key]="";
278286
$data[$key]=$value;
287+
}
279288

280289
return $data;
281290
}
@@ -340,7 +349,7 @@ function to_xml_start(){
340349
$str.=" ".$key."='".$this->xmlentities($value)."'";
341350

342351
if ($this->kids === true)
343-
$str .=" dhx_kids='1'";
352+
$str .=" ".Connector::$kids_var."='1'";
344353

345354
return $str.">";
346355
}
@@ -394,7 +403,11 @@ protected function parse_request(){
394403
/*! renders self as xml, starting part
395404
*/
396405
protected function xml_start(){
397-
return "<data parent='".$this->request->get_relation()."'>";
406+
$attributes = " parent='".$this->request->get_relation()."' ";
407+
foreach($this->attributes as $k=>$v)
408+
$attributes .= " ".$k."='".$v."'";
409+
410+
return "<data".$attributes.">";
398411
}
399412
}
400413

@@ -420,6 +433,10 @@ protected function output_as_xml($res){
420433
if (!empty($this->options))
421434
$data["collections"] = $this->options;
422435

436+
437+
foreach($this->attributes as $k=>$v)
438+
$data[$k] = $v;
439+
423440
$data = json_encode($data);
424441

425442
// return as string
@@ -489,7 +506,7 @@ function to_xml_start(){
489506
$data[$key]=$value;
490507

491508
if ($this->kids === true)
492-
$data["dhx_kids"] = 1;
509+
$data[Connector::$kids_var] = 1;
493510

494511
return $data;
495512
}

codebase/dataprocessor.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,15 @@ protected function inner_process($action){
160160

161161
$mode = $this->status_to_mode($action->get_status());
162162
if (!$this->connector->access->check($mode)){
163-
LogMaster::log("Access control: {$operation} operation blocked");
163+
LogMaster::log("Access control: {$mode} operation blocked");
164164
$action->error();
165165
} else {
166166
$check = $this->connector->event->trigger("beforeProcessing",$action);
167167
if (!$action->is_ready())
168168
$this->check_exts($action,$mode);
169+
if ($mode == "insert" && $action->get_status() != "error" && $action->get_status() != "invalid")
170+
$this->connector->sql->new_record_order($action, $this->request);
171+
169172
$check = $this->connector->event->trigger("afterProcessing",$action);
170173
}
171174

@@ -178,13 +181,14 @@ protected function inner_process($action){
178181

179182
if ($this->connector->sql->is_record_transaction()){
180183
if ($action->get_status()=="error" || $action->get_status()=="invalid")
181-
$this->connector->sql->rollback_transaction();
184+
$this->connector->sql->rollback_transaction();
182185
else
183-
$this->connector->sql->commit_transaction();
186+
$this->connector->sql->commit_transaction();
184187
}
185-
188+
186189
return $action;
187190
}
191+
188192
/*! check if some event intercepts processing, send data to DataWrapper in other case
189193
190194
@param action
@@ -220,7 +224,7 @@ function check_exts($action,$mode){
220224
}
221225
$this->connector->event->trigger("after".$mode,$action);
222226

223-
$this->config = $old_config;
227+
$this->config->copy($old_config);
224228
}
225229

226230
/*! output xml response for dataprocessor
@@ -484,11 +488,23 @@ function success($id=false){
484488
function to_xml(){
485489
$str="<action type='{$this->status}' sid='{$this->id}' tid='{$this->nid}' ";
486490
foreach ($this->attrs as $k => $v) {
487-
$str.=$k."='".$v."' ";
491+
$str.=$k."='".$this->xmlentities($v)."' ";
488492
}
489493
$str.=">{$this->output}</action>";
490494
return $str;
491495
}
496+
497+
/*! replace xml unsafe characters
498+
499+
@param string
500+
string to be escaped
501+
@return
502+
escaped string
503+
*/
504+
public function xmlentities($string) {
505+
return str_replace( array( '&', '"', "'", '<', '>', '' ), array( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;', '&apos;' ), $string);
506+
}
507+
492508
/*! convert self to string ( for logs )
493509
494510
@return

codebase/dataview_connector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ protected function xml_start(){
6060
foreach($this->attributes as $k=>$v)
6161
$attributes .= " ".$k."='".$v."'";
6262

63-
$start.= ">";
6463
if ($this->dload){
6564
if ($pos=$this->request->get_start())
6665
return "<data pos='".$pos."'".$attributes.">";

0 commit comments

Comments
 (0)