summaryrefslogtreecommitdiffstats
path: root/codebase/connector
diff options
context:
space:
mode:
authorAlexKlimenkov <shurick.klimenkov@gmail.com>2014-06-10 20:50:30 +0300
committerAlexKlimenkov <shurick.klimenkov@gmail.com>2014-06-10 20:50:30 +0300
commitb5a0589955460a44c5428c4cb5429fcfce265d23 (patch)
tree87db58400a3e036de646fb630cbb358beeac3bc1 /codebase/connector
parente2aaaef8540fabd0b5200a4959c269d6f1ae352e (diff)
downloadscheduler-b5a0589955460a44c5428c4cb5429fcfce265d23.zip
scheduler-b5a0589955460a44c5428c4cb5429fcfce265d23.tar.gz
scheduler-b5a0589955460a44c5428c4cb5429fcfce265d23.tar.bz2
[update] version 4.1.0
Diffstat (limited to 'codebase/connector')
-rw-r--r--codebase/connector/base_connector.php32
-rw-r--r--codebase/connector/combo_connector.php2
-rw-r--r--codebase/connector/data_connector.php38
-rw-r--r--codebase/connector/dataprocessor.php26
-rw-r--r--codebase/connector/dataview_connector.php1
-rw-r--r--codebase/connector/db_common.php84
-rw-r--r--codebase/connector/db_oracle.php4
-rw-r--r--codebase/connector/gantt_connector.php364
-rw-r--r--codebase/connector/grid_connector.php2
-rw-r--r--codebase/connector/strategy.php18
-rw-r--r--codebase/connector/tree_connector.php3
-rw-r--r--codebase/connector/treegrid_connector.php2
-rw-r--r--codebase/connector/treegridmultitable_connector.php2
13 files changed, 544 insertions, 34 deletions
diff --git a/codebase/connector/base_connector.php b/codebase/connector/base_connector.php
index ac25b00..26f1f8b 100644
--- a/codebase/connector/base_connector.php
+++ b/codebase/connector/base_connector.php
@@ -290,6 +290,7 @@ class Connector {
public static $filter_var="dhx_filter";
public static $sort_var="dhx_sort";
+ public static $kids_var="dhx_kids";
public $model=false;
@@ -312,7 +313,8 @@ class Connector {
protected $filters;
protected $sorts;
protected $mix;
-
+ protected $order = false;
+
/*! constructor
Here initilization of all Masters occurs, execution timer initialized
@@ -599,16 +601,20 @@ class Connector {
$this->request->set_sort($this->resolve_parameter($k),$v);
}
- if (isset($_GET[Connector::$sort_var]))
+ if (isset($_GET[Connector::$filter_var]))
foreach($_GET[Connector::$filter_var] as $k => $v){
$k = $this->safe_field_name($k);
- $this->request->set_filter($this->resolve_parameter($k),$v);
+ if ($v !== "")
+ $this->request->set_filter($this->resolve_parameter($k),$v);
}
+ $this->check_csrf();
+ }
+
+ protected function check_csrf(){
$key = ConnectorSecurity::checkCSRF($this->editing);
if ($key !== "")
$this->add_top_attribute(ConnectorSecurity::$security_var, $key);
-
}
/*! convert incoming request name to the actual DB name
@@ -704,7 +710,23 @@ class Connector {
*/
public function dynamic_loading($count){
$this->dload=$count;
- }
+ }
+
+ /*! enable or disable data reordering
+
+ @param name
+ name of field, which will be used for order storing, optional
+ by default 'sortorder' field will be used
+ */
+ public function enable_order($name = true){
+ if ($name === true)
+ $name = "sortorder";
+
+ $this->sort($name);
+ $this->access->allow("order");
+ $this->request->set_order($name);
+ $this->order = $name;
+ }
/*! enable logging
diff --git a/codebase/connector/combo_connector.php b/codebase/connector/combo_connector.php
index 35c66e9..ad28017 100644
--- a/codebase/connector/combo_connector.php
+++ b/codebase/connector/combo_connector.php
@@ -25,7 +25,7 @@ class ComboDataItem extends DataItem{
function to_xml_start(){
if ($this->skip) return "";
- return "<option ".($this->selected?"selected='true'":"")."value='".$this->get_id()."'><![CDATA[".$this->data[$this->config->text[0]["name"]]."]]>";
+ return "<option ".($this->selected?"selected='true' ":"")."value='".$this->get_id()."'><![CDATA[".$this->data[$this->config->text[0]["name"]]."]]>";
}
/*! return self as XML string, ending part
*/
diff --git a/codebase/connector/data_connector.php b/codebase/connector/data_connector.php
index caa5369..7c9251d 100644
--- a/codebase/connector/data_connector.php
+++ b/codebase/connector/data_connector.php
@@ -113,6 +113,12 @@ class DataConnector extends Connector{
$this->sections[$name] = $string;
}
+ protected function parse_request_mode(){
+ if (isset($_GET['action']) && $_GET["action"] != "get")
+ $this->editing = true;
+ else
+ parent::parse_request_mode();
+ }
//parse GET scoope, all operations with incoming request must be done here
protected function parse_request(){
@@ -131,10 +137,10 @@ class DataConnector extends Connector{
//data saving
$this->editing = true;
}
+ parent::check_csrf();
} else {
if (isset($_GET['editing']) && isset($_POST['ids']))
$this->editing = true;
-
parent::parse_request();
}
@@ -146,7 +152,10 @@ class DataConnector extends Connector{
/*! renders self as xml, starting part
*/
protected function xml_start(){
- $start = parent::xml_start();
+ $start = "<data";
+ foreach($this->attributes as $k=>$v)
+ $start .= " ".$k."='".$v."'";
+ $start.= ">";
foreach($this->sections as $k=>$v)
$start .= "<".$k.">".$v."</".$k.">\n";
@@ -192,7 +201,7 @@ class JSONDataConnector extends DataConnector{
$name = $k;
$option="\"{$name}\":[";
if (!is_string($this->options[$name]))
- $option.=substr($this->options[$name]->render(),0,-2);
+ $option.=substr(json_encode($this->options[$name]->render()),1,-1);
else
$option.=$this->options[$name];
$option.="]";
@@ -260,7 +269,7 @@ class JSONCommonDataItem extends DataItem{
/*! return self as XML string
*/
function to_xml(){
- if ($this->skip) return "";
+ if ($this->skip) return false;
$data = array(
'id' => $this->get_id()
@@ -271,8 +280,11 @@ class JSONCommonDataItem extends DataItem{
}
if ($this->userdata !== false)
- foreach ($this->userdata as $key => $value)
+ foreach ($this->userdata as $key => $value){
+ if ($value === null)
+ $data[$key]="";
$data[$key]=$value;
+ }
return $data;
}
@@ -337,7 +349,7 @@ class TreeCommonDataItem extends CommonDataItem{
$str.=" ".$key."='".$this->xmlentities($value)."'";
if ($this->kids === true)
- $str .=" dhx_kids='1'";
+ $str .=" ".Connector::$kids_var."='1'";
return $str.">";
}
@@ -391,7 +403,11 @@ class TreeDataConnector extends DataConnector{
/*! renders self as xml, starting part
*/
protected function xml_start(){
- return "<data parent='".$this->request->get_relation()."'>";
+ $attributes = " parent='".$this->request->get_relation()."' ";
+ foreach($this->attributes as $k=>$v)
+ $attributes .= " ".$k."='".$v."'";
+
+ return "<data".$attributes.">";
}
}
@@ -417,6 +433,10 @@ class JSONTreeDataConnector extends TreeDataConnector{
if (!empty($this->options))
$data["collections"] = $this->options;
+
+ foreach($this->attributes as $k=>$v)
+ $data[$k] = $v;
+
$data = json_encode($data);
// return as string
@@ -472,7 +492,7 @@ class JSONTreeCommonDataItem extends TreeCommonDataItem{
/*! return self as XML string
*/
function to_xml_start(){
- if ($this->skip) return "";
+ if ($this->skip) return false;
$data = array( "id" => $this->get_id() );
for ($i=0; $i<sizeof($this->config->text); $i++){
@@ -486,7 +506,7 @@ class JSONTreeCommonDataItem extends TreeCommonDataItem{
$data[$key]=$value;
if ($this->kids === true)
- $data["dhx_kids"] = 1;
+ $data[Connector::$kids_var] = 1;
return $data;
}
diff --git a/codebase/connector/dataprocessor.php b/codebase/connector/dataprocessor.php
index e75fc85..26f778b 100644
--- a/codebase/connector/dataprocessor.php
+++ b/codebase/connector/dataprocessor.php
@@ -160,12 +160,15 @@ class DataProcessor{
$mode = $this->status_to_mode($action->get_status());
if (!$this->connector->access->check($mode)){
- LogMaster::log("Access control: {$operation} operation blocked");
+ LogMaster::log("Access control: {$mode} operation blocked");
$action->error();
} else {
$check = $this->connector->event->trigger("beforeProcessing",$action);
if (!$action->is_ready())
$this->check_exts($action,$mode);
+ if ($mode == "insert" && $action->get_status() != "error" && $action->get_status() != "invalid")
+ $this->connector->sql->new_record_order($action, $this->request);
+
$check = $this->connector->event->trigger("afterProcessing",$action);
}
@@ -178,13 +181,14 @@ class DataProcessor{
if ($this->connector->sql->is_record_transaction()){
if ($action->get_status()=="error" || $action->get_status()=="invalid")
- $this->connector->sql->rollback_transaction();
+ $this->connector->sql->rollback_transaction();
else
- $this->connector->sql->commit_transaction();
+ $this->connector->sql->commit_transaction();
}
-
+
return $action;
}
+
/*! check if some event intercepts processing, send data to DataWrapper in other case
@param action
@@ -484,11 +488,23 @@ class DataAction{
function to_xml(){
$str="<action type='{$this->status}' sid='{$this->id}' tid='{$this->nid}' ";
foreach ($this->attrs as $k => $v) {
- $str.=$k."='".$v."' ";
+ $str.=$k."='".$this->xmlentities($v)."' ";
}
$str.=">{$this->output}</action>";
return $str;
}
+
+ /*! replace xml unsafe characters
+
+ @param string
+ string to be escaped
+ @return
+ escaped string
+ */
+ public function xmlentities($string) {
+ return str_replace( array( '&', '"', "'", '<', '>', '’' ), array( '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;', '&apos;' ), $string);
+ }
+
/*! convert self to string ( for logs )
@return
diff --git a/codebase/connector/dataview_connector.php b/codebase/connector/dataview_connector.php
index 41b7387..fe2c9fd 100644
--- a/codebase/connector/dataview_connector.php
+++ b/codebase/connector/dataview_connector.php
@@ -60,7 +60,6 @@ class DataViewConnector extends Connector{
foreach($this->attributes as $k=>$v)
$attributes .= " ".$k."='".$v."'";
- $start.= ">";
if ($this->dload){
if ($pos=$this->request->get_start())
return "<data pos='".$pos."'".$attributes.">";
diff --git a/codebase/connector/db_common.php b/codebase/connector/db_common.php
index 76748e7..e2f521e 100644
--- a/codebase/connector/db_common.php
+++ b/codebase/connector/db_common.php
@@ -14,6 +14,7 @@ class DataRequestConfig{
private $start; //!< start of requested data
private $count; //!< length of requested data
+ private $order = false;
private $user;
private $version;
@@ -83,6 +84,12 @@ class DataRequestConfig{
}
+ public function get_order(){
+ return $this->order;
+ }
+ public function set_order($order){
+ $this->order = $order;
+ }
public function get_user(){
return $this->user;
}
@@ -642,6 +649,73 @@ abstract class DBDataWrapper extends DataWrapper{
return $str;
}
+ public function new_record_order($action, $source){
+ $order = $source->get_order();
+ if ($order){
+ $table = $source->get_source();
+ $id = $this->config->id["db_name"];
+ $idvalue = $action->get_new_id();
+
+ $max = $this->queryOne("SELECT MAX($order) as dhx_maxvalue FROM $table");
+ $dhx_maxvalue = $max["dhx_maxvalue"] + 1;
+
+ $this->query("UPDATE $table SET $order = $dhx_maxvalue WHERE $id = $idvalue");
+ }
+ }
+
+ public function order($data, $source){
+ //id of moved item
+ $id1 = $this->escape($data->get_value("id"));
+ //id of target item
+ $target = $data->get_value("target");
+ if (strpos($target, "next:") !== false){
+ $dropnext = true;
+ $id2 = str_replace("next:", "", $target);
+ } else {
+ $id2 = $target;
+ }
+ $id2 = $this->escape($id2);
+
+
+ //for tree like components we need to limit out queries to the affected branch only
+ $relation_select = $relation_update = $relation_sql_out = $relation_sql = "";
+ if ($this->config->relation_id["name"]){
+ $relation = $data->get_value($this->config->relation_id["name"]);
+ if ($relation !== false && $relation !== ""){
+ $relation_sql = " ".$this->config->relation_id["db_name"]." = '".$this->escape($relation)."' AND ";
+ $relation_select = $this->config->relation_id["db_name"]." as dhx_parent, ";
+ $relation_update = " ".$this->config->relation_id["db_name"]." = '".$this->escape($relation)."', ";
+ }
+ }
+
+
+ $name = $source->get_order();
+ $table = $source->get_source();
+ $idkey = $this->config->id["db_name"];
+
+ $source = $this->queryOne("select $relation_select $name as dhx_index from $table where $idkey = '$id1'");
+ $source_index = $source["dhx_index"] ? $source["dhx_index"] : 0;
+ if ($relation_sql)
+ $relation_sql_out = " ".$this->config->relation_id["db_name"]." = '".$this->escape($source["dhx_parent"])."' AND ";
+
+ $this->query("update $table set $name = $name - 1 where $relation_sql_out $name >= $source_index");
+
+ if ($id2 !== ""){
+ $target = $this->queryOne("select $name as dhx_index from $table where $idkey = '$id2'");
+ $target_index = $target["dhx_index"];
+ if (!$target_index)
+ $target_index = 0;
+ if ($dropnext)
+ $target_index += 1;
+ $this->query("update $table set $name = $name + 1 where $relation_sql $name >= $target_index");
+ } else {
+ $target = $this->queryOne("select max($name) as dhx_index from $table");
+ $target_index = ($target["dhx_index"] ? $target["dhx_index"] : 0)+1;
+ }
+
+ $this->query("update $table set $relation_update $name = $target_index where $idkey = '$id1'");
+ }
+
public function insert($data,$source){
$sql=$this->insert_query($data,$source);
$this->query($sql);
@@ -726,8 +800,14 @@ abstract class DBDataWrapper extends DataWrapper{
else
array_push($sql,$this->escape_name($rules[$i]["name"])." ".$rules[$i]["operation"]." '".$this->escape($rules[$i]["value"])."'");
}
- if ($relation!==false)
- array_push($sql,$this->escape_name($this->config->relation_id["db_name"])." = '".$this->escape($relation)."'");
+
+ if ($relation !== false && $relation !== ""){
+ $relsql = $this->escape_name($this->config->relation_id["db_name"])." = '".$this->escape($relation)."'";
+ if ($relation == "0")
+ $relsql = "( ".$relsql." OR ".$this->escape_name($this->config->relation_id["db_name"])." IS NULL )";
+
+ array_push($sql,$relsql);
+ }
return implode(" AND ",$sql);
}
/*! convert sorting rules to sql string
diff --git a/codebase/connector/db_oracle.php b/codebase/connector/db_oracle.php
index 064d55a..703d3a4 100644
--- a/codebase/connector/db_oracle.php
+++ b/codebase/connector/db_oracle.php
@@ -23,8 +23,8 @@ class OracleDBDataWrapper extends DBDataWrapper{
$mode = ($this->is_record_transaction() || $this->is_global_transaction())?OCI_DEFAULT:OCI_COMMIT_ON_SUCCESS;
- $res=oci_execute($stm,$mode);
- if ($res===false) throw new Exception("Oracle - sql execution failed\n".oci_error($this->connection));
+ $res = @oci_execute($stm,$mode);
+ if ($res===false) throw new Exception(oci_error($this->connection));
$this->last_id=$out[0];
diff --git a/codebase/connector/gantt_connector.php b/codebase/connector/gantt_connector.php
new file mode 100644
index 0000000..74b8636
--- /dev/null
+++ b/codebase/connector/gantt_connector.php
@@ -0,0 +1,364 @@
+<?php
+/*
+ @author dhtmlx.com
+ @license GPL, see license.txt
+*/
+require_once("base_connector.php");
+require_once("data_connector.php");
+
+/*! DataItem class for Gantt component
+**/
+class GanttDataItem extends DataItem{
+
+ /*! return self as XML string
+ */
+ function to_xml(){
+ if ($this->skip) return "";
+
+ $str="<task id='".$this->get_id()."' >";
+ $str.="<start_date><![CDATA[".$this->data[$this->config->text[0]["name"]]."]]></start_date>";
+ $str.="<".$this->config->text[1]["name"]."><![CDATA[".$this->data[$this->config->text[1]["name"]]."]]></".$this->config->text[1]["name"].">";
+ $str.="<text><![CDATA[".$this->data[$this->config->text[2]["name"]]."]]></text>";
+ for ($i=3; $i<sizeof($this->config->text); $i++){
+ $extra = $this->config->text[$i]["name"];
+ $str.="<".$extra."><![CDATA[".$this->data[$extra]."]]></".$extra.">";
+ }
+ if ($this->userdata !== false)
+ foreach ($this->userdata as $key => $value)
+ $str.="<".$key."><![CDATA[".$value."]]></".$key.">";
+
+ return $str."</task>";
+ }
+}
+
+
+/*! Connector class for dhtmlxGantt
+**/
+class GanttConnector extends Connector{
+
+ protected $extra_output="";//!< extra info which need to be sent to client side
+ protected $options=array();//!< hash of OptionsConnector
+ protected $links_mode = false;
+
+
+ /*! assign options collection to the column
+
+ @param name
+ name of the column
+ @param options
+ array or connector object
+ */
+ public function set_options($name,$options){
+ if (is_array($options)){
+ $str="";
+ foreach($options as $k => $v)
+ $str.="<item value='".$this->xmlentities($k)."' label='".$this->xmlentities($v)."' />";
+ $options=$str;
+ }
+ $this->options[$name]=$options;
+ }
+
+
+ /*! constructor
+
+ Here initilization of all Masters occurs, execution timer initialized
+ @param res
+ db connection resource
+ @param type
+ string , which hold type of database ( MySQL or Postgre ), optional, instead of short DB name, full name of DataWrapper-based class can be provided
+ @param item_type
+ name of class, which will be used for item rendering, optional, DataItem will be used by default
+ @param data_type
+ name of class which will be used for dataprocessor calls handling, optional, DataProcessor class will be used by default.
+ * @param render_type
+ name of class which will be used for rendering.
+ */
+ public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
+ if (!$item_type) $item_type="GanttDataItem";
+ if (!$data_type) $data_type="GanttDataProcessor";
+ if (!$render_type) $render_type="RenderStrategy";
+ parent::__construct($res,$type,$item_type,$data_type,$render_type);
+
+ $this->event->attach("afterDelete", array($this, "delete_related_links"));
+ $this->event->attach("afterOrder", array($this, "order_set_parent"));
+ }
+
+ //parse GET scoope, all operations with incoming request must be done here
+ function parse_request(){
+ parent::parse_request();
+
+ if (isset($_GET["gantt_mode"]) && $_GET["gantt_mode"] == "links")
+ $this->links_mode = true;
+
+ if (count($this->config->text)){
+ if (isset($_GET["to"]))
+ $this->request->set_filter($this->config->text[0]["name"],$_GET["to"],"<");
+ if (isset($_GET["from"]))
+ $this->request->set_filter($this->config->text[1]["name"],$_GET["from"],">");
+ }
+ }
+
+ function order_set_parent($action){
+ $value = $action->get_id();
+ $parent = $action->get_value("parent");
+
+ $table = $this->request->get_source();
+ $id = $this->config->id["db_name"];
+
+ $this->sql->query("UPDATE $table SET parent = $parent WHERE $id = $value");
+ }
+
+ function delete_related_links($action){
+ if (isset($this->options["links"])){
+ $links = $this->options["links"];
+ $value = $this->sql->escape($action->get_new_id());
+ $table = $links->get_request()->get_source();
+
+ $this->sql->query("DELETE FROM $table WHERE source = '$value'");
+ $this->sql->query("DELETE FROM $table WHERE target = '$value'");
+ }
+ }
+
+ public function render_links($table,$id="",$fields=false,$extra=false,$relation_id=false) {
+ $links = new GanttLinksConnector($this->get_connection(),$this->names["db_class"]);
+ $links->render_table($table,$id,$fields,$extra);
+ $this->set_options("links", $links);
+ }
+}
+
+/*! DataProcessor class for Gantt component
+**/
+class GanttDataProcessor extends DataProcessor{
+ function name_data($data){
+ if ($data=="start_date")
+ return $this->config->text[0]["db_name"];
+ if ($data=="id")
+ return $this->config->id["db_name"];
+ if ($data=="duration" && $this->config->text[1]["name"] == "duration")
+ return $this->config->text[1]["db_name"];
+ if ($data=="end_date" && $this->config->text[1]["name"] == "end_date")
+ return $this->config->text[1]["db_name"];
+ if ($data=="text")
+ return $this->config->text[2]["db_name"];
+
+ return $data;
+ }
+}
+
+
+class JSONGanttDataItem extends GanttDataItem{
+ /*! return self as XML string
+ */
+ function to_xml(){
+ if ($this->skip) return "";
+
+ $obj = array();
+ $obj['id'] = $this->get_id();
+ $obj['start_date'] = $this->data[$this->config->text[0]["name"]];
+ $obj[$this->config->text[1]["name"]] = $this->data[$this->config->text[1]["name"]];
+ $obj['text'] = $this->data[$this->config->text[2]["name"]];
+ for ($i=3; $i<sizeof($this->config->text); $i++){
+ $extra = $this->config->text[$i]["name"];
+ $obj[$extra]=$this->data[$extra];
+ }
+
+ if ($this->userdata !== false)
+ foreach ($this->userdata as $key => $value)
+ $obj[$key]=$value;
+
+ return $obj;
+ }
+}
+
+
+class JSONGanttConnector extends GanttConnector {
+
+ protected $data_separator = ",";
+
+ /*! constructor
+
+ Here initilization of all Masters occurs, execution timer initialized
+ @param res
+ db connection resource
+ @param type
+ string , which hold type of database ( MySQL or Postgre ), optional, instead of short DB name, full name of DataWrapper-based class can be provided
+ @param item_type
+ name of class, which will be used for item rendering, optional, DataItem will be used by default
+ @param data_type
+ name of class which will be used for dataprocessor calls handling, optional, DataProcessor class will be used by default.
+ */
+ public function __construct($res,$type=false,$item_type=false,$data_type=false,$render_type=false){
+ if (!$item_type) $item_type="JSONGanttDataItem";
+ if (!$data_type) $data_type="GanttDataProcessor";
+ if (!$render_type) $render_type="JSONRenderStrategy";
+ parent::__construct($res,$type,$item_type,$data_type,$render_type);
+ }
+
+ protected function xml_start() {
+ return '{ "data":';
+ }
+
+ protected function xml_end() {
+ $this->fill_collections();
+ $end = (!empty($this->extra_output)) ? ', "collections": {'.$this->extra_output.'}' : '';
+ foreach ($this->attributes as $k => $v)
+ $end.=", \"".$k."\":\"".$v."\"";
+ $end .= '}';
+ return $end;
+ }
+
+ /*! assign options collection to the column
+
+ @param name
+ name of the column
+ @param options
+ array or connector object
+ */
+ public function set_options($name,$options){
+ if (is_array($options)){
+ $str=array();
+ foreach($options as $k => $v)
+ $str[]='{"id":"'.$this->xmlentities($k).'", "value":"'.$this->xmlentities($v).'"}';
+ $options=implode(",",$str);
+ }
+ $this->options[$name]=$options;
+ }
+
+
+ /*! generates xml description for options collections
+
+ @param list
+ comma separated list of column names, for which options need to be generated
+ */
+ protected function fill_collections($list=""){
+ $options = array();
+ foreach ($this->options as $k=>$v) {
+ $name = $k;
+ $option="\"{$name}\":[";
+ if (!is_string($this->options[$name])){
+ $data = json_encode($this->options[$name]->render());
+ $option.=substr($data,1,-1);
+ } else
+ $option.=$this->options[$name];
+ $option.="]";
+ $options[] = $option;
+ }
+ $this->extra_output .= implode($this->data_separator, $options);
+ }
+
+
+ /*! output fetched data as XML
+ @param res
+ DB resultset
+ */
+ protected function output_as_xml($res){
+ $result = $this->render_set($res);
+ if ($this->simple) return $result;
+
+ $data=$this->xml_start().json_encode($result).$this->xml_end();
+
+ if ($this->as_string) return $data;
+
+ $out = new OutputWriter($data, "");
+ $out->set_type("json");
+ $this->event->trigger("beforeOutput", $this, $out);
+ $out->output("", true, $this->encoding);
+ }
+
+ public function render_links($table,$id="",$fields=false,$extra=false,$relation_id=false) {
+ $links = new JSONGanttLinksConnector($this->get_connection(),$this->names["db_class"]);
+ $links->render_table($table,$id,$fields,$extra);
+ $this->set_options("links", $links);
+ }
+
+
+ /*! render self
+ process commands, output requested data as XML
+ */
+ public function render(){
+ $this->event->trigger("onInit", $this);
+ EventMaster::trigger_static("connectorInit",$this);
+
+ if (!$this->as_string)
+ $this->parse_request();
+ $this->set_relation();
+
+ if ($this->live_update !== false && $this->updating!==false) {
+ $this->live_update->get_updates();
+ } else {
+ if ($this->editing){
+ if ($this->links_mode && isset($this->options["links"])) {
+ $this->options["links"]->save();
+ } else {
+ $dp = new $this->names["data_class"]($this,$this->config,$this->request);
+ $dp->process($this->config,$this->request);
+ }
+ } else {
+ if (!$this->access->check("read")){
+ LogMaster::log("Access control: read operation blocked");
+ echo "Access denied";
+ die();
+ }
+ $wrap = new SortInterface($this->request);
+ $this->apply_sorts($wrap);
+ $this->event->trigger("beforeSort",$wrap);
+ $wrap->store();
+
+ $wrap = new FilterInterface($this->request);
+ $this->apply_filters($wrap);
+ $this->event->trigger("beforeFilter",$wrap);
+ $wrap->store();
+
+ if ($this->model && method_exists($this->model, "get")){
+ $this->sql = new ArrayDBDataWrapper();
+ $result = new ArrayQueryWrapper(call_user_func(array($this->model, "get"), $this->request));
+ $out = $this->output_as_xml($result);
+ } else {
+ $out = $this->output_as_xml($this->get_resource());
+
+ if ($out !== null) return $out;
+ }
+
+ }
+ }
+ $this->end_run();
+ }
+}
+
+
+class GanttLinksConnector extends OptionsConnector {
+ public function render(){
+ if (!$this->init_flag){
+ $this->init_flag=true;
+ return "";
+ }
+
+ $res = $this->sql->select($this->request);
+ return $this->render_set($res);
+ }
+
+ public function save() {
+ $dp = new $this->names["data_class"]($this,$this->config,$this->request);
+ $dp->process($this->config,$this->request);
+ }
+}
+
+
+class JSONGanttLinksConnector extends JSONOptionsConnector {
+ public function render(){
+ if (!$this->init_flag){
+ $this->init_flag=true;
+ return "";
+ }
+
+ $res = $this->sql->select($this->request);
+ return $this->render_set($res);
+ }
+
+ public function save() {
+ $dp = new $this->names["data_class"]($this,$this->config,$this->request);
+ $dp->process($this->config,$this->request);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/codebase/connector/grid_connector.php b/codebase/connector/grid_connector.php
index 9748dee..10a98bd 100644
--- a/codebase/connector/grid_connector.php
+++ b/codebase/connector/grid_connector.php
@@ -87,7 +87,7 @@ class GridDataItem extends DataItem{
public function to_xml_start(){
if ($this->skip) return "";
- $str="<row id='".$this->get_id()."'";
+ $str="<row id='".$this->xmlentities($this->get_id())."'";
foreach ($this->row_attrs as $k=>$v)
$str.=" ".$k."='".$v."'";
$str.=">";
diff --git a/codebase/connector/strategy.php b/codebase/connector/strategy.php
index eb579b8..f9a106f 100644
--- a/codebase/connector/strategy.php
+++ b/codebase/connector/strategy.php
@@ -46,7 +46,7 @@ class RenderStrategy {
protected function simple_mix($mix, $data) {
// get mix details
for ($i = 0; $i < count($mix); $i++)
- $data[$mix[$i]["name"]] = is_string($mix[$i]["value"]) ? $mix[$i]["value"] : "";
+ $data[$mix[$i]["name"]] = is_object($mix[$i]["value"]) ? "" : $mix[$i]["value"];
return $data;
}
@@ -130,7 +130,9 @@ class JSONRenderStrategy extends RenderStrategy {
if ($data->get_id()===false)
$data->set_id($conn->uuid());
$conn->event->trigger("beforeRender",$data);
- $output[]=$data->to_xml();
+ $item = $data->to_xml();
+ if ($item !== false)
+ $output[]=$item;
$index++;
}
$this->unmix($config, $mix);
@@ -153,6 +155,7 @@ class TreeRenderStrategy extends RenderStrategy {
$output="";
$index=0;
$conn = $this->conn;
+ $config_copy = new DataConfig($config);
$this->mix($config, $mix);
while ($data=$conn->sql->get_next($res)){
$data = $this->simple_mix($mix, $data);
@@ -166,8 +169,9 @@ class TreeRenderStrategy extends RenderStrategy {
$output.=$data->to_xml_start();
if ($data->has_kids()===-1 || ( $data->has_kids()==true && !$dload)){
$sub_request = new DataRequestConfig($conn->get_request());
+ //$sub_request->set_fieldset(implode(",",$config_copy->db_names_list($conn->sql)));
$sub_request->set_relation($data->get_id());
- $output.=$this->render_set($conn->sql->select($sub_request), $name, $dload, $sep, $config);
+ $output.=$this->render_set($conn->sql->select($sub_request), $name, $dload, $sep, $config_copy, $mix);
}
$output.=$data->to_xml_end();
$index++;
@@ -205,6 +209,7 @@ class JSONTreeRenderStrategy extends TreeRenderStrategy {
$output=array();
$index=0;
$conn = $this->conn;
+ $config_copy = new DataConfig($config);
$this->mix($config, $mix);
while ($data=$conn->sql->get_next($res)){
$data = $this->complex_mix($mix, $data);
@@ -218,12 +223,15 @@ class JSONTreeRenderStrategy extends TreeRenderStrategy {
$record = $data->to_xml_start();
if ($data->has_kids()===-1 || ( $data->has_kids()==true && !$dload)){
$sub_request = new DataRequestConfig($conn->get_request());
+ //$sub_request->set_fieldset(implode(",",$config_copy->db_names_list($conn->sql)));
$sub_request->set_relation($data->get_id());
- $temp = $this->render_set($conn->sql->select($sub_request), $name, $dload, $sep, $config, $mix);
+ //$sub_request->set_filters(array());
+ $temp = $this->render_set($conn->sql->select($sub_request), $name, $dload, $sep, $config_copy, $mix);
if (sizeof($temp))
$record["data"] = $temp;
}
- $output[] = $record;
+ if ($record !== false)
+ $output[] = $record;
$index++;
}
$this->unmix($config, $mix);
diff --git a/codebase/connector/tree_connector.php b/codebase/connector/tree_connector.php
index 6383ff7..154f02a 100644
--- a/codebase/connector/tree_connector.php
+++ b/codebase/connector/tree_connector.php
@@ -198,7 +198,8 @@ class TreeConnector extends Connector{
/*! renders self as xml, ending part
*/
public function xml_end(){
- return "</tree>";
+ $this->fill_collections();
+ return $this->extra_output."</tree>";
}
}
diff --git a/codebase/connector/treegrid_connector.php b/codebase/connector/treegrid_connector.php
index f074879..0bb19ea 100644
--- a/codebase/connector/treegrid_connector.php
+++ b/codebase/connector/treegrid_connector.php
@@ -90,7 +90,7 @@ class TreeGridConnector extends GridConnector{
/*! renders self as xml, starting part
*/
protected function xml_start(){
- return "<rows parent='".$this->request->get_relation()."'>";
+ return "<rows parent='".$this->xmlentities( $this->request->get_relation() )."'>";
}
}
diff --git a/codebase/connector/treegridmultitable_connector.php b/codebase/connector/treegridmultitable_connector.php
index c380ef6..3f4bbd9 100644
--- a/codebase/connector/treegridmultitable_connector.php
+++ b/codebase/connector/treegridmultitable_connector.php
@@ -27,7 +27,7 @@ class TreeGridMultitableConnector extends TreeGridConnector{
public function xml_start(){
if (isset($_GET['id'])) {
- return "<rows parent='".$this->render->level_id($_GET['id'], $this->get_level() - 1)."'>";
+ return "<rows parent='".$this->xmlentities($this->render->level_id($_GET['id'], $this->get_level() - 1))."'>";
} else {
return "<rows parent='0'>";
}