| @@ -435,8 +435,8 @@ class page_action extends tform_actions { | |||
| //print "<pre> BBDD "; print_r($paramsBD); print "</pre>\n"; | |||
| $this->nombre_db_txt = $paramsBD['database_name']; | |||
| $db_id = $remoto->sites_database_add($this->cli_grupo_id, /*$this->cli_id,*//*$fields['client_group_id'],*/ $paramsBD); | |||
| //IMPORTANTE. COMPROBAR EL VALOR QUE HAY QUE ENVIAR, SI ES CLI GRUPO Ó CLI ID | |||
| // $db_id = $remoto->sites_database_add(/*$this->cli_grupo_id,*/ $this->cli_id,/*$fields['client_group_id'],*/ $paramsBD); | |||
| $this->urlBBDD($db_id, $this->bbdd_serv); | |||
| //echo('Id de la BBDD ' . $db_id); | |||
| @@ -592,30 +592,41 @@ class page_action extends tform_actions { | |||
| $fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true); | |||
| //Captura de los distintos ids del cliente y usuario de sistema. | |||
| //combinando un query a las dos tablas sys_group y sys_user que comparten el client_id. | |||
| //print "<pre>Seleccionado: "; print_r($fields['client_group_id']); print "</pre>\n"; | |||
| if($fields['client_group_id']==0) { | |||
| //En la tabla sys_user el client_id 0 es admin. En sys_group este valor es 0 | |||
| $this->cli_id = 0; | |||
| //En la tabla dns_soa y dns_rr se guarda el valor 0 en sys_groupid cuando es admin. | |||
| $this->cli_grupo_id = 0; | |||
| $this->sys_usuario_id = 1;//$this->cli_id; | |||
| $this->sys_grupo_id = 0;//$this->cli_grupo_id; | |||
| }else{ | |||
| $client = $app->db->queryOneRecord( | |||
| 'SELECT sys_user.sys_userid, sys_user.sys_groupid, sys_user.default_group, sys_user.client_id | |||
| FROM sys_group, sys_user | |||
| WHERE sys_group.client_id = sys_user.client_id and sys_group.groupid = ?', $fields['client_group_id']); | |||
| $this->cli_id = $client['client_id']; | |||
| $this->cli_grupo_id = $client['default_group']; | |||
| $this->sys_usuario_id = $client['sys_userid']; | |||
| $this->sys_grupo_id = $client['sys_groupid']; | |||
| } | |||
| //* Client: If the logged in user is not admin and has no sub clients (no reseller) | |||
| if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { | |||
| $this->cli_id = $_SESSION["s"]["user"]["client_id"]; | |||
| $this->cli_grupo_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); | |||
| $this->sys_usuario_id = $_SESSION["s"]["user"]["sys_userid"]; | |||
| $this->sys_grupo_id = $_SESSION["s"]["user"]["sys_groupid"]; | |||
| //echo('Es cliente cli_id ' . $this->cli_id . ' cli_grupo_id ' . $this->cli_grupo_id . ' sys_usuario ' . $this->sys_usuario_id . ' sys_grupo ' . $this->sys_grupo_id); | |||
| } else { | |||
| //Captura de los distintos ids del cliente y usuario de sistema. | |||
| //combinando un query a las dos tablas sys_group y sys_user que comparten el client_id. | |||
| //print "<pre>Seleccionado: "; print_r($fields['client_group_id']); print "</pre>\n"; | |||
| if($fields['client_group_id']==0) { | |||
| //En la tabla sys_user el client_id 0 es admin. En sys_group este valor es 0 | |||
| $this->cli_id = 0; | |||
| $this->cli_grupo_id = 1; | |||
| $this->sys_usuario_id = 1;//$this->cli_id; | |||
| $this->sys_grupo_id = 0; //$this->cli_grupo_id;//0 | |||
| //echo('Quien es ' . $_SESSION["s"]["user"]["typ"]); | |||
| }else{ | |||
| //echo('Quien es else ' . $_SESSION["s"]["user"]["typ"]); | |||
| $client = $app->db->queryOneRecord( | |||
| 'SELECT sys_user.sys_userid, sys_user.sys_groupid, sys_user.default_group, sys_user.client_id | |||
| FROM sys_group, sys_user | |||
| WHERE sys_group.client_id = sys_user.client_id and sys_group.groupid = ?', $fields['client_group_id']); | |||
| $this->cli_id = $client['client_id']; | |||
| $this->cli_grupo_id = $client['default_group']; | |||
| $this->sys_usuario_id = $client['sys_userid']; | |||
| $this->sys_grupo_id = $this->cli_grupo_id;//$client['sys_groupid']; | |||
| } | |||
| } | |||
| //print "<pre>Valores : "; print_r($this->cli_id); print "</pre>\n"; | |||
| //print "Valores " . $this->cli_id . ' ' . $this->cli_grupo_id . ' ' . $this->sys_usuario_id . ' ' . $this->sys_grupo_id; | |||
| //print " cli_id " . $this->cli_id . ' cli_grupo ' . $this->cli_grupo_id . ' sys_usuario ' . $this->sys_usuario_id . ' sys grupo ' . $this->sys_grupo_id; | |||
| } | |||
| @@ -1242,24 +1253,19 @@ class page_action extends tform_actions { | |||
| function existeDominio($campos){ | |||
| global $app, $conf; | |||
| //if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin LIKE "'.$campos['domain'].'%"')) { | |||
| if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin = "'.$campos['domain'].'."')) { | |||
| $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique_webdns']; | |||
| $this->onError(); | |||
| return true; | |||
| if($app->db->queryOneRecord('SELECT * FROM dns_soa WHERE origin LIKE "'.$campos['domain'].'."')) { | |||
| $app->tform->errorMessage = $app->tform->wordbook['domain_error_unique']; | |||
| } | |||
| if($app->db->queryOneRecord('SELECT domain_id, domain FROM web_domain WHERE domain = "'.$campos['domain'].'"')) { | |||
| $app->tform->errorMessage = $app->tform->wordbook['error_sitio_web_existe']; | |||
| $this->onError(); | |||
| return true; | |||
| } | |||
| /*if($app->tform->errorsMessage) | |||
| //IMPORTANTE. AQUI CONTROLAMOS LOS ERRORES QUE SE VALIDAN EN EL FORMULARIO, EN ESTE CASO EL CAMPO DEL DOMINIO. | |||
| if($app->tform->errorMessage) | |||
| { | |||
| $this->onError(); | |||
| return true; | |||
| }*/ | |||
| } | |||
| } | |||
| public $ip4_ultima; | |||
| @@ -1571,7 +1577,146 @@ print "<pre>IP6 WEB ";print_r($this->ip6_servidor_web);print "</pre>\n";*/ | |||
| class remote_actions extends remoting { | |||
| public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') { | |||
| return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier); | |||
| global $app; | |||
| /*$sql = $this->insertQueryPrepare($formdef_file, $client_id, $params); | |||
| echo(' Query ' . $sql); | |||
| $app->uses('remoting_lib'); | |||
| $app->remoting_lib->loadUserProfile();*/ | |||
| //return $app->db->query($sql);//$this->insertQueryExecute($sql, $params, $event_identifier); | |||
| //echo(' insertQueryPrepare ' . $this->insertQueryExecute($sql, $params, $event_identifier)); | |||
| return $this->insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier); | |||
| //return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier); | |||
| } | |||
| function insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier = '') { | |||
| $sql = $this->insertQueryPrepareWebDNS($formdef_file, $client_id, $params); | |||
| if($sql !== false) return $this->insertQueryExecuteWebDNS($sql, $params, $event_identifier); | |||
| else return false; | |||
| } | |||
| function insertQueryPrepareWebDNS($formdef_file, $client_id, $params) { | |||
| global $app; | |||
| $app->uses('remoting_lib'); | |||
| //* load the user profile of the client | |||
| //$app->remoting_lib->loadUserProfile($client_id); | |||
| //* Load the form definition | |||
| $app->remoting_lib->loadFormDef($formdef_file); | |||
| //echo(' Base de datos ' . $app->remoting_lib->loadFormDef($formdef_file)); | |||
| //* Get the SQL query | |||
| $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0); | |||
| /*if($app->remoting_lib->errorMessage != '') { | |||
| throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage); | |||
| return false; | |||
| }*/ | |||
| $app->log('Executed insertQueryPrepareWebDNS', LOGLEVEL_DEBUG); | |||
| return $sql; | |||
| } | |||
| function insertQueryExecuteWebDNS($sql, $params, $event_identifier = '') { | |||
| global $app; | |||
| $app->uses('remoting_lib'); | |||
| $app->db->query($sql); | |||
| /*if($app->db->errorMessage != '') { | |||
| throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql); | |||
| return false; | |||
| }*/ | |||
| if ( isset($params['_primary_id'] )) | |||
| $insert_id = $params['_primary_id']; | |||
| else | |||
| $insert_id = $app->db->insertID(); | |||
| // set a few values for compatibility with tform actions, mostly used by plugins | |||
| $this->id = $insert_id; | |||
| $this->dataRecord = $params; | |||
| $app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG); | |||
| if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this); | |||
| //$app->uses('tform'); | |||
| //* Save changes to Datalog | |||
| if($app->remoting_lib->formDef["db_history"] == 'yes') { | |||
| //$new_rec = $app->remoting_lib->getDataRecord($insert_id); | |||
| $new_rec = $this->getDataRecordWebDNS($insert_id); | |||
| $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec); | |||
| } | |||
| return $insert_id; | |||
| } | |||
| function getDataRecordWebDNS($primary_id) { | |||
| global $app; | |||
| $escape = '`'; | |||
| //$this->loadUserProfile(); | |||
| if(@is_numeric($primary_id)) { | |||
| if($primary_id > 0) { | |||
| // Return a single record | |||
| return $this->getDataRecordPadreWebDNS($primary_id); | |||
| //return parent::getDataRecord($primary_id); | |||
| } elseif($primary_id == -1) { | |||
| // Return a array with all records | |||
| $sql = "SELECT * FROM ??"; | |||
| return $app->db->queryAllRecords($sql, $this->formDef['db_table']); | |||
| } else { | |||
| throw new SoapFault('invalid_id', 'The ID has to be > 0 or -1.'); | |||
| return array(); | |||
| } | |||
| } elseif (@is_array($primary_id) || @is_object($primary_id)) { | |||
| if(@is_object($primary_id)) $primary_id = get_object_vars($primary_id); // do not use cast (array)xxx because it returns private and protected properties! | |||
| $sql_offset = 0; | |||
| $sql_limit = 0; | |||
| $sql_where = ''; | |||
| $params = array($this->formDef['db_table']); | |||
| foreach($primary_id as $key => $val) { | |||
| if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val); | |||
| elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val); | |||
| elseif(stristr($val, '%')) { | |||
| $sql_where .= "?? like ? AND "; | |||
| } else { | |||
| $sql_where .= "?? = ? AND "; | |||
| } | |||
| $params[] = $key; | |||
| $params[] = $val; | |||
| } | |||
| $sql_where = substr($sql_where, 0, -5); | |||
| if($sql_where == '') $sql_where = '1'; | |||
| $sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQLWebDNS('r', $this->formDef['db_table']); | |||
| if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit; | |||
| return $app->db->queryAllRecords($sql, true, $params); | |||
| } else { | |||
| $this->errorMessage = 'The ID must be either an integer or an array.'; | |||
| return array(); | |||
| } | |||
| } | |||
| function getDataRecordPadreWebDNS($primary_id) { | |||
| global $app; | |||
| $escape = '`'; | |||
| $sql = "SELECT * FROM ?? WHERE ?? = ? AND ".$this->getAuthSQLWebDNS('r', $this->formDef['db_table']); | |||
| return $app->db->queryOneRecord($sql, $this->formDef['db_table'], $this->formDef['db_table_idx'], $primary_id); | |||
| } | |||
| function getAuthSQLWebDNS($perm, $table = '') { | |||
| if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) { | |||
| return '1'; | |||
| } else { | |||
| if ($table != ''){ | |||
| $table = ' ' . $table . '.'; | |||
| } | |||
| $groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0; | |||
| $sql = '('; | |||
| $sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR "; | |||
| $sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR "; | |||
| $sql .= $table . "sys_perm_other like '%$perm%'"; | |||
| $sql .= ')'; | |||
| return $sql; | |||
| } | |||
| } | |||
| public function sites_database_add($client_id, $params){ | |||