diff --git a/lib/classes/answer.class.php b/lib/classes/answer.class.php index bdfeaebe76..7cbf4bc01a 100644 --- a/lib/classes/answer.class.php +++ b/lib/classes/answer.class.php @@ -71,7 +71,7 @@ class answer $preview = '/include/directprev.php%3F'."bas%3D".$base_id."%26rec%3D".$record_id; $JS_roll = '
- '; + '; } } @@ -256,12 +256,12 @@ class answer $token = md5(time().mt_rand(100000,999999)); $html_view = '
-
+
-
'; + '; - $preview = '
'; + $preview = '
'; // $width = $height = '200'; } elseif(in_array($sdMain[$typedoc]['mime'],$gviewer_docs)) @@ -427,7 +427,7 @@ class answer } return(array($term, $context)); } - + public static function format_caption($base_id, $record_id, $xml, $with_bounce = false, $template=false) { $session = session::getInstance(); @@ -453,7 +453,6 @@ class answer $basesettings = phrasea::load_settings($locale); - $captions = _('reponses::record::Pas de description'); $xsl = ''; @@ -470,8 +469,8 @@ class answer if($dom_doc->loadXML($xml)) { $XPATH_thesaurus = databox::get_xpath_thesaurus($sbas_id); - $XPATH_struct = databox::get_xpath_structure($sbas_id); + $DOM_thFields = array(); if($XPATH_struct) @@ -496,16 +495,16 @@ class answer $context_noacc = noaccent_utf8($context_noacc, PARSED); if($context_noacc) { - $q = "($tbranch)//sy[@w='".$term_noacc."' and @k='".$context_noacc."']"; + $q = "//sy[@w='".$term_noacc."' and @k='".$context_noacc."']"; } else { - $q = "($tbranch)//sy[@w='".$term_noacc."' and not(@k)]"; + $q = "//sy[@w='".$term_noacc."' and not(@k)]"; } $t = ""; foreach($DOM_branchs as $DOM_branch) { - $nodes = $XPATH_thesaurus->query($q, $DOM_branch); + $nodes = $XPATH_thesaurus->cache_query($q, $DOM_branch, $tbranch); if($nodes->length > 0) { $lngfound = false; @@ -529,12 +528,12 @@ class answer $t .= "');return(false);\"]]"; $t .= $fvalue; $t .= "[[/a]]"; - $lngfound = true; break; } - $synonyms = $XPATH_thesaurus->query("sy[@lng='" . $session->usr_i18 . "']", $node->parentNode); + $synonyms = $XPATH_thesaurus->query("sy[@lng='" . $session->usr_i18n . "']", $node->parentNode); + foreach($synonyms as $synonym) { $k = $synonym->getAttribute("k"); @@ -554,7 +553,6 @@ class answer $t .= "');return(false);\"]]"; $t .= $link; $t .= "[[/a]]"; - $lngfound = true; break; } @@ -1203,4 +1201,6 @@ class answer } return($value); } -} \ No newline at end of file +} + + diff --git a/lib/classes/base.class.php b/lib/classes/base.class.php index 6c432f60d0..3e9ec1cb59 100644 --- a/lib/classes/base.class.php +++ b/lib/classes/base.class.php @@ -2,605 +2,604 @@ abstract class base { - var $schema = false; - var $conn = false; - var $dbname = false; - var $passwd = false; - var $user = false; - var $port = false; - var $host = false; - var $type = false; - - - function init_conn() - { - require dirname( __FILE__ ) . '/../../config/connexion.inc'; - $this->conn = mysql_connect($hostname.":".$port, $user, $password, true); - - mysql_set_charset('utf8',$this->conn); - mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->conn); - - if($this->conn !== false) - return true; - - return false; - } - - function __destruct() - { - - } - - - function load_schema($schema_type) - { - $this->schema = false; - $structure = simplexml_load_file(dirname(__FILE__)."/../../lib/conf.d/bases_structure.xml"); - if($structure !== false) - { - if($schema_type === 'application_box') - $this->schema = $structure->appbox; - if($schema_type === 'data_box') - $this->schema = $structure->databox; - } - return $this->schema !== false ? true : false ; - } - - function createDb($dbname) - { - if($this->schema) - { - $sql = 'CREATE DATABASE `'.mysql_real_escape_string($dbname,$this->conn).'` CHARACTER SET utf8 COLLATE utf8_unicode_ci'; - if(mysql_query($sql,$this->conn) || mysql_select_db($dbname,$this->conn)) - { - mysql_select_db($dbname,$this->conn); - - foreach($this->schema->tables->table as $table) - { - $this->createTable($table); - } - - $this->dbname = $dbname; - - if(defined('GV_version')) - $this->setVersion(GV_version); - - return true; - } - else - return false; - - } - return false; - } - - private function createTable($table) - { - $field_stmt = $defaults_stmt = array(); - - $create_stmt = "CREATE TABLE `".mysql_real_escape_string($table['name'],$this->conn)."` ("; - - foreach($table->fields->field as $field){ - - $isnull=trim($field->null)==""?"NOT NULL":"NULL"; - - if(trim($field->default) != "" && trim($field->default)!="CURRENT_TIMESTAMP") - $is_default = " default '".$field->default."'"; - elseif(trim($field->default)=="CURRENT_TIMESTAMP") - $is_default = " default ".$field->default; - else - $is_default = ''; - $character_set = ''; - if(in_array(strtolower((string)$field->type),array('text','longtext','mediumtext','tinytext')) || substr(strtolower((string)$field->type), 0, 7) == 'varchar' || in_array(substr(strtolower((string)$field->type), 0, 4), array('char','enum'))) - { - - $collation = trim((string)$field->collation) != '' ? trim((string)$field->collation) : 'utf8_unicode_ci'; - - $code = array_pop(array_reverse(explode('_',$collation))); - - $character_set = ' CHARACTER SET '.$code.' COLLATE ' . $collation ; - - } - - $field_stmt[] = " `".mysql_real_escape_string($field->name,$this->conn)."` ".$field->type." ".$field->extra." ".$character_set." ".$is_default." ".$isnull.""; - - } - - - if($table->indexes){ - foreach($table->indexes->index as $index){ - switch($index->type){ - - case "PRIMARY":{ - $primary_fields = array(); - - foreach($index->fields->field as $field){ - $primary_fields[] = "`".mysql_real_escape_string($field,$this->conn)."`"; - } - - $field_stmt[] = 'PRIMARY KEY ('.implode(',' , $primary_fields).')'; - };break; - - case "UNIQUE":{ - $unique_fields = array(); - - foreach($index->fields->field as $field){ - $unique_fields[] = "`".mysql_real_escape_string($field,$this->conn)."`"; - } - - $field_stmt[] = 'UNIQUE KEY `'.mysql_real_escape_string($index->name,$this->conn).'` ('.implode(',',$unique_fields).')'; - };break; - - case "INDEX":{ - $index_fields = array(); - - foreach($index->fields->field as $field){ - $index_fields[] = "`".mysql_real_escape_string($field,$this->conn)."`"; - } - - $field_stmt[] = 'KEY `'.mysql_real_escape_string($index->name,$this->conn).'` ('.implode(',',$index_fields).')'; - };break; - - } - - } - } - if($table->defaults){ - foreach($table->defaults->default as $default) - { - - $k = $v = array(); - - foreach($default->data as $data) - { - $k[] = mysql_real_escape_string($data['key'],$this->conn); - if($k === 'usr_password') - $data = hash('sha256',$data); - $v[] = mysql_real_escape_string(trim(str_replace(array("\r\n","\r","\n","\t"),'',$data)),$this->conn); - } - - $k = implode(',',$k); - $v = str_ireplace(array('"NOW()"','"null"'),array('NOW()','null'),'"'.implode('","',$v).'"'); - - - $defaults_stmt[] = 'INSERT INTO '.mysql_real_escape_string($table['name'],$this->conn).' ('.$k.') VALUES ('.$v.') '; - - } - } - - - $engine = mb_strtolower(trim($table->engine)); - - $engine = in_array($engine,array('innodb','myisam')) ? $engine : 'innodb'; - - $create_stmt .= implode(',' , $field_stmt); - $create_stmt .= ") ENGINE=".$engine." CHARACTER SET utf8 COLLATE utf8_unicode_ci;"; - - mysql_query($create_stmt,$this->conn); - - foreach($defaults_stmt as $def) - { - mysql_query($def,$this->conn); - } - - } - - private function upgradeTable($table) - { - $correct_table = array('fields'=>array(), 'indexes'=>array(), 'collation'=>array()); - $alter = $alter_pre = array(); - - if($table) - { - foreach($table->fields->field as $field) - { - $expr = trim((string)$field->type); - - - $_extra = trim((string)$field->extra); - if($_extra) - $expr .= ' ' . $_extra; - - $collation = trim((string)$field->collation) != '' ? trim((string)$field->collation) : 'utf8_unicode_ci'; - - if(in_array(strtolower((string)$field->type),array('text','longtext','mediumtext','tinytext')) || substr(strtolower((string)$field->type), 0, 7) == 'varchar' || in_array(substr(strtolower((string)$field->type), 0, 4), array('char','enum'))) - { - $code = array_pop(array_reverse(explode('_',$collation))); - - $collation = ' CHARACTER SET '.$code.' COLLATE ' . $collation ; - - $correct_table['collation'][trim((string)$field->name)] = $collation ; - - $expr .= $collation; - } - - - - $_null = mb_strtolower(trim((string)$field->null)); - if(!$_null || $_null=='no') - $expr .= ' NOT NULL'; - - $_default = (string)$field->default; - if($_default && $_default != 'CURRENT_TIMESTAMP') - $expr .= ' DEFAULT \'' . $_default . '\''; - elseif($_default == 'CURRENT_TIMESTAMP') - $expr .= ' DEFAULT ' . $_default . ''; - - $correct_table['fields'][trim((string)$field->name)] = $expr; - } - if($table->indexes) - { - foreach($table->indexes->index as $index) - { - $i_name = (string)$index->name; - $expr = array(); - foreach($index->fields->field as $field) - $expr[] = '`'.trim((string)$field).'`'; - - $expr = implode(', ',$expr); - - switch((string)$index->type) - { - case "PRIMARY": - $correct_table['indexes']['PRIMARY'] = 'PRIMARY KEY (' . $expr . ')'; - break; - - case "UNIQUE": - $correct_table['indexes'][$i_name] = 'UNIQUE KEY `' . $i_name . '` (' . $expr . ')'; - break; - - case "INDEX": - $correct_table['indexes'][$i_name] = 'KEY `' . $i_name . '` (' . $expr . ')'; - break; - } - } - } - - - $sql = "SHOW FULL FIELDS FROM `".$table['name']."`"; - if($rs2 = mysql_query($sql,$this->conn)) - { - while( $row2 = mysql_fetch_assoc($rs2) ) - { - $f_name = $row2['Field']; - $expr_found = trim($row2['Type']); - - $_extra = $row2['Extra']; - - if($_extra) - $expr_found .= ' ' . $_extra; + var $schema = false; + var $conn = false; + var $dbname = false; + var $passwd = false; + var $user = false; + var $port = false; + var $host = false; + var $type = false; - $_collation = $row2['Collation']; - - $current_collation = ''; - - if($_collation) - { - $_collation = explode('_',$row2['Collation']); - - $expr_found .= $current_collation = ' CHARACTER SET ' . $_collation[0] . ' COLLATE ' . implode('_', $_collation); - } - - $_null = mb_strtolower(trim($row2['Null'])); - - if(!$_null || $_null=='no') - $expr_found .= ' NOT NULL'; - - $_default = $row2['Default']; - - if($_default) - { - if(trim($row2['Type'])=='timestamp' && $_default=='CURRENT_TIMESTAMP') - $expr_found .= ' DEFAULT CURRENT_TIMESTAMP'; - else - $expr_found .= ' DEFAULT \'' . $_default . '\''; - } - - - if(isset($correct_table['fields'][$f_name])) - { - if(isset($correct_table['collation'][$f_name]) && $correct_table['collation'][$f_name] != $current_collation) - { - - - $old_type = mb_strtolower(trim($row2['Type'])); - $new_type = false; - - switch($old_type) - { - case 'text': - $new_type = 'blob'; - break; - case 'longtext': - $new_type = 'longblob'; - break; - case 'mediumtext': - $new_type = 'mediumblob'; - break; - case 'tinytext': - $new_type = 'tinyblob'; - break; - default: - if(substr($old_type, 0, 4) == 'char') - $new_type = 'varbinary(255)'; - if(substr($old_type, 0, 7) == 'varchar') - $new_type = 'varbinary(767)'; - break; - } - - if($new_type) - { - $alter_pre[] = "ALTER TABLE `".$table['name']."` CHANGE `$f_name` `$f_name` ".$new_type.""; - } - } - - if(strtolower($expr_found) !== strtolower($correct_table['fields'][$f_name])) - { - $alter[] = "ALTER TABLE `".$table['name']."` CHANGE `$f_name` `$f_name` " . $correct_table['fields'][$f_name] ; - } - unset($correct_table['fields'][$f_name]); - } + function init_conn() + { + require dirname(__FILE__) . '/../../config/connexion.inc'; + $this->conn = mysql_connect($hostname . ":" . $port, $user, $password, true); + + mysql_set_charset('utf8', $this->conn); + mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->conn); + + if ($this->conn !== false) + return true; + + return false; + } + + function __destruct() + { + + } + + function load_schema($schema_type) + { + $this->schema = false; + $structure = simplexml_load_file(dirname(__FILE__) . "/../../lib/conf.d/bases_structure.xml"); + if ($structure !== false) + { + if ($schema_type === 'application_box') + $this->schema = $structure->appbox; + if ($schema_type === 'data_box') + $this->schema = $structure->databox; + } + return $this->schema !== false ? true : false; + } + + function createDb($dbname) + { + if ($this->schema) + { + $sql = 'CREATE DATABASE `' . mysql_real_escape_string($dbname, $this->conn) . '` CHARACTER SET utf8 COLLATE utf8_unicode_ci'; + if (mysql_query($sql, $this->conn) || mysql_select_db($dbname, $this->conn)) + { + mysql_select_db($dbname, $this->conn); + + foreach ($this->schema->tables->table as $table) + { + $this->createTable($table); + } + + $this->dbname = $dbname; + + if (defined('GV_version')) + $this->setVersion(GV_version); + + return true; + } + else + return false; + } + return false; + } + + private function createTable($table) + { + $field_stmt = $defaults_stmt = array(); + + $create_stmt = "CREATE TABLE `" . mysql_real_escape_string($table['name'], $this->conn) . "` ("; + + foreach ($table->fields->field as $field) + { + + $isnull = trim($field->null) == "" ? "NOT NULL" : "NULL"; + + if (trim($field->default) != "" && trim($field->default) != "CURRENT_TIMESTAMP") + $is_default = " default '" . $field->default . "'"; + elseif (trim($field->default) == "CURRENT_TIMESTAMP") + $is_default = " default " . $field->default; + else + $is_default = ''; + + $character_set = ''; + if (in_array(strtolower((string) $field->type), array('text', 'longtext', 'mediumtext', 'tinytext')) || substr(strtolower((string) $field->type), 0, 7) == 'varchar' || in_array(substr(strtolower((string) $field->type), 0, 4), array('char', 'enum'))) + { + + $collation = trim((string) $field->collation) != '' ? trim((string) $field->collation) : 'utf8_unicode_ci'; + + $code = array_pop(array_reverse(explode('_', $collation))); + + $character_set = ' CHARACTER SET ' . $code . ' COLLATE ' . $collation; + } + + $field_stmt[] = " `" . mysql_real_escape_string($field->name, $this->conn) . "` " . $field->type . " " . $field->extra . " " . $character_set . " " . $is_default . " " . $isnull . ""; + } + + + if ($table->indexes) + { + foreach ($table->indexes->index as $index) + { + switch ($index->type) + { + + case "PRIMARY": + { + $primary_fields = array(); + + foreach ($index->fields->field as $field) + { + $primary_fields[] = "`" . mysql_real_escape_string($field, $this->conn) . "`"; + } + + $field_stmt[] = 'PRIMARY KEY (' . implode(',', $primary_fields) . ')'; + }; + break; + + case "UNIQUE": + { + $unique_fields = array(); + + foreach ($index->fields->field as $field) + { + $unique_fields[] = "`" . mysql_real_escape_string($field, $this->conn) . "`"; + } + + $field_stmt[] = 'UNIQUE KEY `' . mysql_real_escape_string($index->name, $this->conn) . '` (' . implode(',', $unique_fields) . ')'; + }; + break; + + case "INDEX": + { + $index_fields = array(); + + foreach ($index->fields->field as $field) + { + $index_fields[] = "`" . mysql_real_escape_string($field, $this->conn) . "`"; + } + + $field_stmt[] = 'KEY `' . mysql_real_escape_string($index->name, $this->conn) . '` (' . implode(',', $index_fields) . ')'; + }; + break; + } + } + } + if ($table->defaults) + { + foreach ($table->defaults->default as $default) + { + + $k = $v = array(); + + foreach ($default->data as $data) + { + $k[] = mysql_real_escape_string($data['key'], $this->conn); + if ($k === 'usr_password') + $data = hash('sha256', $data); + $v[] = mysql_real_escape_string(trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $data)), $this->conn); + } + + $k = implode(',', $k); + $v = str_ireplace(array('"NOW()"', '"null"'), array('NOW()', 'null'), '"' . implode('","', $v) . '"'); + + + $defaults_stmt[] = 'INSERT INTO ' . mysql_real_escape_string($table['name'], $this->conn) . ' (' . $k . ') VALUES (' . $v . ') '; + } + } + + + $engine = mb_strtolower(trim($table->engine)); + + $engine = in_array($engine, array('innodb', 'myisam')) ? $engine : 'innodb'; + + $create_stmt .= implode(',', $field_stmt); + $create_stmt .= ") ENGINE=" . $engine . " CHARACTER SET utf8 COLLATE utf8_unicode_ci;"; + + mysql_query($create_stmt, $this->conn); + + foreach ($defaults_stmt as $def) + { + mysql_query($def, $this->conn); + } + } + + private function upgradeTable($table) + { + $correct_table = array('fields' => array(), 'indexes' => array(), 'collation' => array()); + $alter = $alter_pre = array(); + + if ($table) + { + foreach ($table->fields->field as $field) + { + $expr = trim((string) $field->type); + + + $_extra = trim((string) $field->extra); + if ($_extra) + $expr .= ' ' . $_extra; + + $collation = trim((string) $field->collation) != '' ? trim((string) $field->collation) : 'utf8_unicode_ci'; + + if (in_array(strtolower((string) $field->type), array('text', 'longtext', 'mediumtext', 'tinytext')) || substr(strtolower((string) $field->type), 0, 7) == 'varchar' || in_array(substr(strtolower((string) $field->type), 0, 4), array('char', 'enum'))) + { + $code = array_pop(array_reverse(explode('_', $collation))); + + $collation = ' CHARACTER SET ' . $code . ' COLLATE ' . $collation; + + $correct_table['collation'][trim((string) $field->name)] = $collation; + + $expr .= $collation; + } + + + + $_null = mb_strtolower(trim((string) $field->null)); + if (!$_null || $_null == 'no') + $expr .= ' NOT NULL'; + + $_default = (string) $field->default; + if ($_default && $_default != 'CURRENT_TIMESTAMP') + $expr .= ' DEFAULT \'' . $_default . '\''; + elseif ($_default == 'CURRENT_TIMESTAMP') + $expr .= ' DEFAULT ' . $_default . ''; + + $correct_table['fields'][trim((string) $field->name)] = $expr; + } + if ($table->indexes) + { + foreach ($table->indexes->index as $index) + { + $i_name = (string) $index->name; + $expr = array(); + foreach ($index->fields->field as $field) + $expr[] = '`' . trim((string) $field) . '`'; + + $expr = implode(', ', $expr); + + switch ((string) $index->type) + { + case "PRIMARY": + $correct_table['indexes']['PRIMARY'] = 'PRIMARY KEY (' . $expr . ')'; + break; + + case "UNIQUE": + $correct_table['indexes'][$i_name] = 'UNIQUE KEY `' . $i_name . '` (' . $expr . ')'; + break; + + case "INDEX": + $correct_table['indexes'][$i_name] = 'KEY `' . $i_name . '` (' . $expr . ')'; + break; + } + } + } + + + $sql = "SHOW FULL FIELDS FROM `" . $table['name'] . "`"; + if ($rs2 = mysql_query($sql, $this->conn)) + { + while ($row2 = mysql_fetch_assoc($rs2)) + { + $f_name = $row2['Field']; + $expr_found = trim($row2['Type']); + + $_extra = $row2['Extra']; + + if ($_extra) + $expr_found .= ' ' . $_extra; + + $_collation = $row2['Collation']; + + $current_collation = ''; + + if ($_collation) + { + $_collation = explode('_', $row2['Collation']); + + $expr_found .= $current_collation = ' CHARACTER SET ' . $_collation[0] . ' COLLATE ' . implode('_', $_collation); + } + + $_null = mb_strtolower(trim($row2['Null'])); + + if (!$_null || $_null == 'no') + $expr_found .= ' NOT NULL'; + + $_default = $row2['Default']; + + if ($_default) + { + if (trim($row2['Type']) == 'timestamp' && $_default == 'CURRENT_TIMESTAMP') + $expr_found .= ' DEFAULT CURRENT_TIMESTAMP'; + else + $expr_found .= ' DEFAULT \'' . $_default . '\''; + } + + + if (isset($correct_table['fields'][$f_name])) + { + if (isset($correct_table['collation'][$f_name]) && $correct_table['collation'][$f_name] != $current_collation) + { + + + $old_type = mb_strtolower(trim($row2['Type'])); + $new_type = false; + + switch ($old_type) + { + case 'text': + $new_type = 'blob'; + break; + case 'longtext': + $new_type = 'longblob'; + break; + case 'mediumtext': + $new_type = 'mediumblob'; + break; + case 'tinytext': + $new_type = 'tinyblob'; + break; + default: + if (substr($old_type, 0, 4) == 'char') + $new_type = 'varbinary(255)'; + if (substr($old_type, 0, 7) == 'varchar') + $new_type = 'varbinary(767)'; + break; + } + + if ($new_type) + { + $alter_pre[] = "ALTER TABLE `" . $table['name'] . "` CHANGE `$f_name` `$f_name` " . $new_type . ""; + } + } + + if (strtolower($expr_found) !== strtolower($correct_table['fields'][$f_name])) + { + $alter[] = "ALTER TABLE `" . $table['name'] . "` CHANGE `$f_name` `$f_name` " . $correct_table['fields'][$f_name]; + } + unset($correct_table['fields'][$f_name]); + } // else // { // $alter[] = "ALTER TABLE `".$table['name']."` DROP `$f_name`"; // } - } - - foreach($correct_table['fields'] as $f_name=>$expr) - { - $alter[] = "ALTER TABLE `".$table['name']."` ADD `$f_name` " . $correct_table['fields'][$f_name]; - } - - mysql_free_result($rs2); - } - - $tIndex = array(); - $sql = "SHOW INDEXES FROM `".$table['name']."`"; - - if($rs2 = mysql_query($sql,$this->conn)) - { - while( $row2 = mysql_fetch_assoc($rs2) ) - { - if(!isset($tIndex[$row2['Key_name']])) - $tIndex[$row2['Key_name']] = array('unique'=>((int)($row2['Non_unique'])==0), 'columns'=>array()); - $tIndex[$row2['Key_name']]['columns'][(int)($row2['Seq_in_index'])] = $row2['Column_name']; - } - mysql_free_result($rs2); - - foreach($tIndex as $kIndex=>$vIndex) - { - $strColumns = array(); - - foreach($vIndex['columns'] as $column) - $strColumns[] = '`'.$column.'`'; - - $strColumns = '('.implode(', ',$strColumns).')'; - - if($kIndex=='PRIMARY') - $expr_found = 'PRIMARY KEY '.$strColumns; - else - { - if($vIndex['unique']) - $expr_found = 'UNIQUE KEY `' . $kIndex . '` ' .$strColumns; - else - $expr_found = 'KEY `' . $kIndex . '` ' .$strColumns; - } - - $full_name_index = ($kIndex=='PRIMARY') ? 'PRIMARY KEY' : ('INDEX `'.$kIndex.'`'); - - if( isset($correct_table['indexes'][$kIndex]) ) - { - - if(mb_strtolower($expr_found) !== mb_strtolower($correct_table['indexes'][$kIndex])) - { - $alter[] = 'ALTER TABLE `'.$table['name'].'` DROP ' . $full_name_index . ', ADD ' . $correct_table['indexes'][$kIndex]; - } - - unset($correct_table['indexes'][$kIndex]); - } + } + + foreach ($correct_table['fields'] as $f_name => $expr) + { + $alter[] = "ALTER TABLE `" . $table['name'] . "` ADD `$f_name` " . $correct_table['fields'][$f_name]; + } + + mysql_free_result($rs2); + } + + $tIndex = array(); + $sql = "SHOW INDEXES FROM `" . $table['name'] . "`"; + + if ($rs2 = mysql_query($sql, $this->conn)) + { + while ($row2 = mysql_fetch_assoc($rs2)) + { + if (!isset($tIndex[$row2['Key_name']])) + $tIndex[$row2['Key_name']] = array('unique' => ((int) ($row2['Non_unique']) == 0), 'columns' => array()); + $tIndex[$row2['Key_name']]['columns'][(int) ($row2['Seq_in_index'])] = $row2['Column_name']; + } + mysql_free_result($rs2); + + foreach ($tIndex as $kIndex => $vIndex) + { + $strColumns = array(); + + foreach ($vIndex['columns'] as $column) + $strColumns[] = '`' . $column . '`'; + + $strColumns = '(' . implode(', ', $strColumns) . ')'; + + if ($kIndex == 'PRIMARY') + $expr_found = 'PRIMARY KEY ' . $strColumns; + else + { + if ($vIndex['unique']) + $expr_found = 'UNIQUE KEY `' . $kIndex . '` ' . $strColumns; + else + $expr_found = 'KEY `' . $kIndex . '` ' . $strColumns; + } + + $full_name_index = ($kIndex == 'PRIMARY') ? 'PRIMARY KEY' : ('INDEX `' . $kIndex . '`'); + + if (isset($correct_table['indexes'][$kIndex])) + { + + if (mb_strtolower($expr_found) !== mb_strtolower($correct_table['indexes'][$kIndex])) + { + $alter[] = 'ALTER TABLE `' . $table['name'] . '` DROP ' . $full_name_index . ', ADD ' . $correct_table['indexes'][$kIndex]; + } + + unset($correct_table['indexes'][$kIndex]); + } // else // $alter[] = 'ALTER TABLE `'.$table['name'].'` DROP ' . $full_name_index; - } - } - - foreach($correct_table['indexes'] as $kIndex=>$expr) - $alter[] = 'ALTER TABLE `'.$table['name'].'` ADD ' . $expr; - - } - - $return = true; - - foreach($alter_pre as $a) - { - if(!mysql_query($a, $this->conn)) - $return = false; - } - - - foreach($alter as $a) - { - if(!mysql_query($a, $this->conn)) - { - if(GV_debug) - { - echo $a,' -- ',mysql_error($this->conn),'
'; - } - $return = false; - } - } - - return $return; - - } - - - function upgradeDb() - { - require_once dirname( __FILE__ ) . '/../version.inc'; - if($this->schema && $this->dbname) - { - $allTables = array(); + } + } - foreach($this->schema->tables->table as $table) - $allTables[(string)$table['name']] = $table; - - $sql = "SHOW TABLE STATUS"; - if($rs = mysql_query($sql,$this->conn)) - { - while( $row = mysql_fetch_assoc($rs) ) - { - $tname = $row["Name"]; - - if(isset($allTables[$tname])) - { - $engine = strtolower(trim($allTables[$tname]->engine)); - $ref_engine = strtolower($row['Engine']); - - if($engine != $ref_engine && in_array($engine,array('innodb','myisam'))) - { - $sql = 'ALTER TABLE `'.$tname.'` ENGINE = '.$engine; - mysql_query($sql,$this->conn); - } - - self::upgradeTable($allTables[$tname]); - unset($allTables[$tname]); - } - } - mysql_free_result($rs); - } - foreach($allTables as $tname=>$table) - { - $this->createTable($table); - } - } - - $current_version = self::getVersion(); - - - if(self::apply_patches($current_version,GV_version)) - self::setVersion(GV_version); - - return true; - } - - function apply_patches($from,$to) - { - if(version_compare($from,$to,'=')) - return true; - - $list_patches = array(); - - $iterator = new DirectoryIterator(GV_RootPath.'lib/classes/patch/'); - - foreach ($iterator as $fileinfo) - { - if (!$fileinfo->isDot()) - { - if(substr($fileinfo->getFilename(),0,1) == '.') - continue; - - $classname = 'patch_'.array_pop(array_reverse(explode('.',$fileinfo->getFilename()))); - - $patch = new $classname(); - - if(!in_array($this->type, $patch->concern())) - continue; - - if(!version_compare($patch->get_release(), $from, '>') || !version_compare($patch->get_release(), $to, '<=')) - { - continue; - } - - $list_patches[$patch->get_release()][] = $patch; - } - } - ksort($list_patches); - - $success = true; - - foreach($list_patches as $v=>$patches) - { - foreach($patches as $patch) - { - if(!$patch->apply($this->id)) - $success = false; - } - } - - return $success; - } - - - function upgradeAvalaible() - { - if($this->type == 'application_box') - $sql = 'SELECT version FROM sitepreff'; - if($this->type == 'data_box') - $sql = 'SELECT value AS version FROM pref WHERE prop="version" LIMIT 1;'; - - if($sql !== '') - { - if($rs = mysql_query($sql,$this->conn)) - { - if($row = mysql_fetch_assoc($rs)) - $version = $row['version']; - } - } - if(isset($version)) - return version_compare(GV_version,$version,'>'); - else - return true; - } + foreach ($correct_table['indexes'] as $kIndex => $expr) + $alter[] = 'ALTER TABLE `' . $table['name'] . '` ADD ' . $expr; + } + + $return = true; + + foreach ($alter_pre as $a) + { + if (!mysql_query($a, $this->conn)) + $return = false; + } + + + foreach ($alter as $a) + { + if (!mysql_query($a, $this->conn)) + { + if (GV_debug) + { + echo $a, ' -- ', mysql_error($this->conn), '
'; + } + $return = false; + } + } + + return $return; + } + + function upgradeDb() + { + require_once dirname(__FILE__) . '/../version.inc'; + if ($this->schema && $this->dbname) + { + $allTables = array(); + + foreach ($this->schema->tables->table as $table) + $allTables[(string) $table['name']] = $table; + + $sql = "SHOW TABLE STATUS"; + if ($rs = mysql_query($sql, $this->conn)) + { + while ($row = mysql_fetch_assoc($rs)) + { + $tname = $row["Name"]; + + if (isset($allTables[$tname])) + { + $engine = strtolower(trim($allTables[$tname]->engine)); + $ref_engine = strtolower($row['Engine']); + + if ($engine != $ref_engine && in_array($engine, array('innodb', 'myisam'))) + { + $sql = 'ALTER TABLE `' . $tname . '` ENGINE = ' . $engine; + mysql_query($sql, $this->conn); + } + + self::upgradeTable($allTables[$tname]); + unset($allTables[$tname]); + } + } + mysql_free_result($rs); + } + foreach ($allTables as $tname => $table) + { + $this->createTable($table); + } + } + + $current_version = self::getVersion(); + + + if (self::apply_patches($current_version, GV_version)) + self::setVersion(GV_version); + + return true; + } + + function apply_patches($from, $to) + { + if (version_compare($from, $to, '=')) + return true; + + $list_patches = array(); + + $iterator = new DirectoryIterator(GV_RootPath . 'lib/classes/patch/'); + + foreach ($iterator as $fileinfo) + { + if (!$fileinfo->isDot()) + { + if (substr($fileinfo->getFilename(), 0, 1) == '.') + continue; + + $classname = 'patch_' . array_pop(array_reverse(explode('.', $fileinfo->getFilename()))); + + $patch = new $classname(); + + if (!in_array($this->type, $patch->concern())) + continue; + + if (!version_compare($patch->get_release(), $from, '>') || !version_compare($patch->get_release(), $to, '<=')) + { + continue; + } + + $list_patches[$patch->get_release()][] = $patch; + } + } + ksort($list_patches); + + $success = true; + + foreach ($list_patches as $v => $patches) + { + foreach ($patches as $patch) + { + if (!$patch->apply($this->id)) + $success = false; + } + } + + return $success; + } + + function upgradeAvalaible() + { + if ($this->type == 'application_box') + $sql = 'SELECT version FROM sitepreff'; + if ($this->type == 'data_box') + $sql = 'SELECT value AS version FROM pref WHERE prop="version" LIMIT 1;'; + + if ($sql !== '') + { + if ($rs = mysql_query($sql, $this->conn)) + { + if ($row = mysql_fetch_assoc($rs)) + $version = $row['version']; + } + } + if (isset($version)) + return version_compare(GV_version, $version, '>'); + else + return true; + } + + private function setVersion($version) + { + $sql = ''; + if ($this->type == 'application_box') + $sql = 'UPDATE sitepreff SET version = "' . $version . '"'; + if ($this->type == 'data_box') + { + $sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL'; + mysql_query($sql, $this->conn); + $sql = 'REPLACE INTO pref (id, prop, value,locale, updated_on) VALUES (null, "version", "' . $version . '","", NOW())'; + } + + if ($sql !== '') + { + if (mysql_query($sql, $this->conn)) + return true; + } + + return false; + } + + public function getVersion() + { + $sql = ''; + if ($this->type == 'application_box') + $sql = 'SELECT version FROM sitepreff'; + if ($this->type == 'data_box') + { + $sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL'; + mysql_query($sql, $this->conn); + $sql = 'SELECT value AS version FROM pref WHERE prop="version" LIMIT 1;'; + } + + if ($sql !== '') + { + if ($rs = mysql_query($sql, $this->conn)) + { + if ($row = mysql_fetch_assoc($rs)) + { + return $row['version']; + } + } + } + + return '0.0.0'; + } - private function setVersion($version) - { - $sql = ''; - if($this->type == 'application_box') - $sql = 'UPDATE sitepreff SET version = "'.$version.'"'; - if($this->type == 'data_box') - { - $sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL'; - mysql_query($sql,$this->conn); - $sql = 'REPLACE INTO pref (id, prop, value,locale, updated_on) VALUES (null, "version", "'.$version.'","", NOW())'; - } - - if($sql !== '') - { - if(mysql_query($sql,$this->conn)) - return true; - } - - return false; - } - - public function getVersion() - { - $sql = ''; - if($this->type == 'application_box') - $sql = 'SELECT version FROM sitepreff'; - if($this->type == 'data_box') - { - $sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL'; - mysql_query($sql,$this->conn); - $sql = 'SELECT value AS version FROM pref WHERE prop="version" LIMIT 1;'; - } - - if($sql !== '') - { - if($rs = mysql_query($sql,$this->conn)) - { - if($row = mysql_fetch_assoc($rs)) - { - return $row['version']; - } - } - } - - return '0.0.0'; - } - - - - } diff --git a/lib/classes/connection.class.php b/lib/classes/connection.class.php index e94e128df4..48563cc4ec 100755 --- a/lib/classes/connection.class.php +++ b/lib/classes/connection.class.php @@ -1,11 +1,21 @@ isok()) -// { -// header("HTTP/1.0 500 Internal Server Error"); -// die('

HTTP/1.0 500 Internal Server Error

Can\'t establish database connection

'); -// } - return array_key_exists($name, self::$_instance) ? self::$_instance[$name] : false; } + /** + * + * @param string $name + * @return PDO + */ + public static function getPDOConnection($name = null) + { + if (!isset(self::$_PDO_instance[$name])) + { + $hostname = $port = $user = $password = $dbname = false; + + $connection_params = array(); + + if (trim($name) !== '') + { + $connection_params = phrasea::sbas_params(); + } + else + { + require (dirname(__FILE__) . '/../../config/connexion.inc'); + $name = 'app_box'; + } + + if (isset($connection_params[$name])) + { + $hostname = $connection_params[$name]['host']; + $port = $connection_params[$name]['port']; + $user = $connection_params[$name]['user']; + $password = $connection_params[$name]['pwd']; + $dbname = $connection_params[$name]['dbname']; + } + + $dsn = 'mysql:dbname=' . $dbname . ';host=' . $hostname.';port='.$port.';'; + + try + { + self::$_PDO_instance[$name] = new PDO($dsn, $user, $password); + self::$_PDO_instance[$name]->query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); + } + catch (Exception $e) + { + throw new Exception('Connection not avalaible'); + } + } + if (array_key_exists($name, self::$_PDO_instance)) + return self::$_PDO_instance[$name]; + throw new Exception('Connection not avalaible'); + } + function __construct($name) { diff --git a/lib/classes/databox.class.php b/lib/classes/databox.class.php index 312c432e25..70cfd79678 100644 --- a/lib/classes/databox.class.php +++ b/lib/classes/databox.class.php @@ -1,664 +1,684 @@ $host, - 'port'=>$port, - 'user'=>$user, - 'password'=>$password - ); - - if($this->init_data_conn($newServer) === false) - return false; - - if($this->load_schema('data_box')=== false) - return false; - - if($id !== false) - $this->load((int)$id); - - $this->type = 'data_box'; + var $structure = false; + private static $_xpath_thesaurus = array(); + private static $_dom_thesaurus = array(); + private static $_thesaurus = array(); + private static $_xpath_structure = array(); + private static $_dom_structure = array(); + private static $_sxml_structure = array(); + private static $_sxml_thesaurus = array(); - return true; - } - - function load($id) - { - - $conn = connection::getInstance(); - $sql = 'SELECT dbname FROM sbas WHERE sbas_id="'.$id.'"'; - if($rs = $conn->query($sql)) - { - if($row = $conn->fetch_assoc($rs)) - { - $this->id = $id; - if(mysql_select_db($row['dbname'],$this->conn)) - $this->dbname = $row['dbname']; - } - $conn->free_result($rs); - } -// $sql = 'SELECT value FROM pref WHERE prop="mail_request"'; -// if($rs = mysql_query($sql,$this->conn)) -// { -// while($row = mysql_fetch_assoc($rs)) -// { -// $this->request_mails[] = $row['value']; -// } -// mysql_free_result($rs); -// } - - return false; - } - - function __destruct() - { - - return true; - } - - public function get_mountable_colls() - { - $conn = connection::getInstance(); - $colls = array(); - - $sql = 'SELECT server_coll_id FROM bas WHERE sbas_id="'.$conn->escape_string($this->id).'"'; - if($rs = $conn->query($sql)) - { - while($row = $conn->fetch_assoc($rs)) - $colls[] = $row['server_coll_id']; - $conn->free_result($rs); - } - - $connbas = connection::getInstance($this->id); - - $mountable_colls = array(); - - $sql = 'SELECT coll_id, asciiname FROM coll WHERE coll_id NOT IN ('.implode(',', $colls).')'; - - if($rs = $connbas->query($sql)) - { - while($row = $connbas->fetch_assoc($rs)) - $mountable_colls[$row['coll_id']] = $row['asciiname']; - $connbas->free_result($rs); - } - - return $mountable_colls; - } - - public function list_colls() - { - $lb = phrasea::bases(); - - $colls = array(); - - foreach($lb['bases'] as $base) - { - if($base['sbas_id'] != $this->id) - continue; - foreach($base['collections'] as $coll) - { - $colls[$coll['base_id']] = $coll['name']; - } - } - return $colls; - } - - public function save($usr_id) - { - $conn = connection::getInstance(); - if($this->id === false) - { - if(trim($this->dbname) == '') - throw new Exception('invalid dbname'); - if(trim($this->user) == '') - throw new Exception('invalid user'); - if(trim($this->host) == '') - throw new Exception('invalid host'); - - $ord = 0; - $sql = '(SELECT MAX(ord) as ord FROM sbas)'; - if($rs = $conn->query($sql)) - { - if($row = mysql_fetch_assoc($rs)) - $ord = $row['ord']+1; - } - - $sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd) VALUES (null, "'.$ord.'", "'.$conn->escape_string($this->host).'", "'.$conn->escape_string($this->port).'", "'.$conn->escape_string($this->dbname).'", "MYSQL", "'.$conn->escape_string($this->user).'", "'.mysql_real_escape_string($this->passwd).'")'; - - if($conn->query($sql)) - { - $this->id = $conn->insert_id(); - - $sql = 'INSERT INTO sbasusr (sbasusr_id, sbas_id, usr_id, bas_manage, bas_modify_struct, bas_modif_th, bas_chupub) VALUES (null, "'.$this->id.'", "'.$usr_id.'", "0", "0", "0", "0")'; - $conn->query($sql); - } - else - throw new Exception('unable to save databox in sbasusr : '.$conn->last_error()); - } - - return $this->id; - } - - function create($dbname) - { - $this->createDb($dbname); - $cache_appbox = cache_appbox::getInstance(); - $cache_appbox->delete('list_bases'); - cache_databox::update($this->id,'structure'); - } - - function mount($dbname, $usr_id) - { - $conn = connection::getInstance(); - if(mysql_select_db($dbname,$this->conn)) - { - $this->dbname = $dbname; - if($this->save($usr_id) !== false) - { - $cache_appbox = cache_appbox::getInstance(); - - - $sql = "SELECT * FROM coll"; - if($rs = mysql_query($sql, $this->conn)) - { - $base_id = $this->getAppboxId('BAS', mysql_num_rows($rs)); - - - while($row = mysql_fetch_assoc($rs)) - { - if(!empty($row['logo']) && ($fp = fopen(GV_RootPath.'config/minilogos/'.$base_id, 'w')) !== false) - { - fwrite($fp, $row["logo"]); - fclose($fp); - } - - $sql = "INSERT INTO bas + function __construct($id=false, $host=false, $port=false, $user=false, $password=false) + { + $newServer = false; + if ($host !== false && $port !== false && $user !== false && $password !== false) + $newServer = array( + 'hostname' => $host, + 'port' => $port, + 'user' => $user, + 'password' => $password + ); + elseif ($id !== false) + { + try + { + $conn = connection::getPDOConnection(); + $sql = 'SELECT host, port, user, pwd FROM sbas WHERE sbas_id= :sbas_id'; + $stmt = $conn->prepare($sql); + $stmt->execute(array(':sbas_id' => $id)); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $newServer = array( + 'hostname' => $row['host'], + 'port' => $row['port'], + 'user' => $row['user'], + 'password' => $row['pwd'] + ); + } + catch (Exception $e) + { + + } + } + + if ($this->init_data_conn($newServer) === false) + return false; + + if ($this->load_schema('data_box') === false) + return false; + + if ($id !== false) + $this->load((int) $id); + + $this->type = 'data_box'; + + return true; + } + + function load($id) + { + + $conn = connection::getInstance(); + $sql = 'SELECT dbname FROM sbas WHERE sbas_id="' . $id . '"'; + if ($rs = $conn->query($sql)) + { + if ($row = $conn->fetch_assoc($rs)) + { + $this->id = $id; + if (mysql_select_db($row['dbname'], $this->conn)) + $this->dbname = $row['dbname']; + } + $conn->free_result($rs); + } + + return false; + } + + function __destruct() + { + + return true; + } + + public function get_mountable_colls() + { + $conn = connection::getInstance(); + $colls = array(); + + $sql = 'SELECT server_coll_id FROM bas WHERE sbas_id="' . $conn->escape_string($this->id) . '"'; + if ($rs = $conn->query($sql)) + { + while ($row = $conn->fetch_assoc($rs)) + $colls[] = $row['server_coll_id']; + $conn->free_result($rs); + } + + $connbas = connection::getInstance($this->id); + + $mountable_colls = array(); + + $sql = 'SELECT coll_id, asciiname FROM coll WHERE coll_id NOT IN (' . implode(',', $colls) . ')'; + + if ($rs = $connbas->query($sql)) + { + while ($row = $connbas->fetch_assoc($rs)) + $mountable_colls[$row['coll_id']] = $row['asciiname']; + $connbas->free_result($rs); + } + + return $mountable_colls; + } + + public function list_colls() + { + $lb = phrasea::bases(); + + $colls = array(); + + foreach ($lb['bases'] as $base) + { + if ($base['sbas_id'] != $this->id) + continue; + foreach ($base['collections'] as $coll) + { + $colls[$coll['base_id']] = $coll['name']; + } + } + return $colls; + } + + public function save($usr_id) + { + $conn = connection::getInstance(); + if ($this->id === false) + { + if (trim($this->dbname) == '') + throw new Exception('invalid dbname'); + if (trim($this->user) == '') + throw new Exception('invalid user'); + if (trim($this->host) == '') + throw new Exception('invalid host'); + + $ord = 0; + $sql = '(SELECT MAX(ord) as ord FROM sbas)'; + if ($rs = $conn->query($sql)) + { + if ($row = mysql_fetch_assoc($rs)) + $ord = $row['ord'] + 1; + } + + $sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd) VALUES (null, "' . $ord . '", "' . $conn->escape_string($this->host) . '", "' . $conn->escape_string($this->port) . '", "' . $conn->escape_string($this->dbname) . '", "MYSQL", "' . $conn->escape_string($this->user) . '", "' . mysql_real_escape_string($this->passwd) . '")'; + + if ($conn->query($sql)) + { + $this->id = $conn->insert_id(); + + $sql = 'INSERT INTO sbasusr (sbasusr_id, sbas_id, usr_id, bas_manage, bas_modify_struct, bas_modif_th, bas_chupub) VALUES (null, "' . $this->id . '", "' . $usr_id . '", "0", "0", "0", "0")'; + $conn->query($sql); + } + else + throw new Exception('unable to save databox in sbasusr : ' . $conn->last_error()); + } + + return $this->id; + } + + function create($dbname) + { + $this->createDb($dbname); + $cache_appbox = cache_appbox::getInstance(); + $cache_appbox->delete('list_bases'); + cache_databox::update($this->id, 'structure'); + } + + function mount($dbname, $usr_id) + { + $conn = connection::getInstance(); + if (mysql_select_db($dbname, $this->conn)) + { + $this->dbname = $dbname; + if ($this->save($usr_id) !== false) + { + $cache_appbox = cache_appbox::getInstance(); + + + $sql = "SELECT * FROM coll"; + if ($rs = mysql_query($sql, $this->conn)) + { + $base_id = $this->getAppboxId('BAS', mysql_num_rows($rs)); + + + while ($row = mysql_fetch_assoc($rs)) + { + if (!empty($row['logo']) && ($fp = fopen(GV_RootPath . 'config/minilogos/' . $base_id, 'w')) !== false) + { + fwrite($fp, $row["logo"]); + fclose($fp); + } + + $sql = "INSERT INTO bas (base_id, active, server_coll_id, sbas_id) VALUES - ('".$conn->escape_string($base_id)."','1', - '".$conn->escape_string($row['coll_id'])."','".$conn->escape_string($this->id)."')"; - if($conn->query($sql)) - { - - $sql = "INSERT INTO basusr + ('" . $conn->escape_string($base_id) . "','1', + '" . $conn->escape_string($row['coll_id']) . "','" . $conn->escape_string($this->id) . "')"; + if ($conn->query($sql)) + { + + $sql = "INSERT INTO basusr (base_id, usr_id, canpreview, canpush, canhd, cancmd, canputinalbum, candwnldhd, candwnldpreview, canadmin, actif, canreport, canaddrecord, canmodifrecord, candeleterecord, chgstatus, imgtools, manage, modify_struct, mask_and, mask_xor, basusr_infousr, creationdate ) VALUES - ('".$base_id."', '".$usr_id."', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '0', '0', '', NOW())"; + ('" . $base_id . "', '" . $usr_id . "', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '0', '0', '', NOW())"; - $conn->query($sql); - } - - $base_id++; - } - $cache_appbox->delete('list_bases'); - cache_databox::update($this->id,'structure'); - } - return $this->id; - } - } - return false; - } - - public function saveStructure() - { - - } - - private function getAppboxId($typeId, $askfor_n=1) - { - $x = null; - - $conn = connection::getInstance(); - - $sql = 'LOCK TABLE uids WRITE'; - if($conn->query($sql)) - { - $sql = "UPDATE uids SET uid=uid+$askfor_n WHERE name='$typeId'" ; - if($conn->query($sql)) - { - $sql = "SELECT uid FROM uids WHERE name='$typeId'"; - if($result = $conn->query($sql)) - { - if($row = mysql_fetch_assoc($result)) - $x = ($row["uid"]-$askfor_n)+1; - mysql_free_result($result); - } - } - $sql = 'UNLOCK TABLES'; - $conn->query($sql); - } - return $x; - } + $conn->query($sql); + } - private function init_data_conn($new_db=false) - { - // just in case - if(is_resource($this->conn)) - { - mysql_close($this->conn); - $this->conn = false; - } - - // connect to appbox - require dirname( __FILE__ ) . '/../../config/connexion.inc'; - - $conn = connection::getInstance(); - - if($conn) - { - - if(!$new_db) - { - // same as appbox - $this->host = $hostname; - $this->port = $port; - $this->user = $user; - $this->passwd = $password; - } - else - { - $this->host = $new_db['hostname']; - $this->port = $new_db['port']; - $this->user = $new_db['user']; - $this->passwd = $new_db['password']; - } - - $this->conn = mysql_connect($this->host.":".$this->port, $this->user, $this->passwd, true ); - - mysql_set_charset('utf8',$this->conn); - mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->conn); - - if($this->conn !== false) - return true; - } - return false; - } - - public function setNewStructure($data_template,$path_web,$path_doc,$baseurl) - { - if(is_file($data_template)) - { - $contents = file_get_contents($data_template); - - $contents = str_replace( - array("{{dataurl}}" , "{{basename}}" , "{{datapathweb}}" , "{{datapathnoweb}}"), - array($baseurl , $this->dbname, $path_web, $path_doc ), - $contents - ); - - $this->structure = $contents; - - $sql = 'UPDATE pref SET value="'.mysql_real_escape_string($this->structure,$this->conn).'", updated_on=NOW() WHERE prop="structure"'; - if(mysql_query($sql,$this->conn)) - return true; - } - - return false; - } - - public function registerAdmin($usr_id,$bool) - { - $conn = connection::getInstance(); - $sql = 'UPDATE sbasusr SET bas_manage="'.($bool === true ? '1' : '0').'" WHERE usr_id = "'.$usr_id.'" AND sbas_id="'.$this->id.'"'; - if($conn->query($sql)) - return true; - return false; - } - - public function registerAdminStruct($usr_id,$bool) - { - $conn = connection::getInstance(); - $sql = 'UPDATE sbasusr SET bas_modify_struct="'.($bool === true ? '1' : '0').'" WHERE usr_id = "'.$usr_id.'" AND sbas_id="'.$this->id.'"'; - if($conn->query($sql)) - return true; - return false; - } - - public function registerAdminThesaurus($usr_id,$bool) - { - $conn = connection::getInstance(); - $sql = 'UPDATE sbasusr SET bas_modif_th="'.($bool === true ? '1' : '0').'" WHERE usr_id = "'.$usr_id.'" AND sbas_id="'.$this->id.'"'; - if($conn->query($sql)) - return true; - return false; - } - - public function registerPublication($usr_id,$bool) - { - $conn = connection::getInstance(); - $sql = 'UPDATE sbasusr SET bas_chupub="'.($bool === true ? '1' : '0').'" WHERE usr_id = "'.$usr_id.'" AND sbas_id="'.$this->id.'"'; - if($conn->query($sql)) - return true; - return false; - } + $base_id++; + } + $cache_appbox->delete('list_bases'); + cache_databox::update($this->id, 'structure'); + } + return $this->id; + } + } + return false; + } - - public static function printStatus($name) - { - - $cache_data = cache_appbox::getInstance(); - - if(($tmp = $cache_data->get('status'.$name)) !== false) - return $tmp; - - $filename = GV_RootPath.'config/status/'.$name; - - $out = ''; - - if(is_file($filename)) - { - $out = file_get_contents($filename); - } - - $cache_data->set('status'.$name,$out); - - return $out; - } + public function saveStructure() + { + + } - public static function getPrintLogo($sbas_id) - { - - $cache_data = cache_appbox::getInstance(); - - $out = ''; - if(is_file( ($filename = GV_RootPath.'config/minilogos/logopdf_'.$sbas_id.'.jpg') )) - $out = file_get_contents($filename); - - return $out; - } + private function getAppboxId($typeId, $askfor_n=1) + { + $x = null; - public static function getColls($sbas_id=false) - { - $tbas = array(); - $conn = connection::getInstance(); - - if($sbas_id !== false) - $sql = "SELECT * FROM sbas s, bas b WHERE s.sbas_id='".$conn->escape_string($sbas_id)."' AND s.sbas_id = b.sbas_id AND b.active = '1' ORDER BY s.ord ASC, b.ord ASC"; - else - $sql = "SELECT * FROM sbas s, bas b WHERE s.sbas_id = b.sbas_id AND b.active = '1' ORDER BY s.ord ASC, b.ord ASC"; - - if($rs = $conn->query($sql)) - { - while($row = $conn->fetch_assoc($rs)) - { - if(!isset($tbas[$row["sbas_id"]])) - { - $tbas[$row["sbas_id"]] = array('viewname'=>(trim($row['viewname']) != '' ?$row['viewname'] : $row['dbname']), 'colls'=>array()); - - $connbas = connection::getInstance($row['sbas_id']); - if($connbas) - { - $sql = "SELECT coll_id, asciiname FROM coll"; - if($rsbas = $connbas->query($sql)) - { - while($rowbas = $connbas->fetch_assoc($rsbas)) - { - $colls[$row['sbas_id']][$rowbas["coll_id"]] = $rowbas['asciiname']; - } - $conn->free_result($rsbas); - } - } - } - $tbas[$row["sbas_id"]]['colls'][$row['base_id']] = isset($colls[$row['sbas_id']][$row['server_coll_id']]) ? $colls[$row['sbas_id']][$row['server_coll_id']] : 'unknown name'; - } - $conn->free_result($rs); - } - return($tbas); - } + $conn = connection::getInstance(); - - public static function get_dom_thesaurus($sbas_id) - { - if(isset(self::$_dom_thesaurus[$sbas_id])) - { - return self::$_dom_thesaurus[$sbas_id]; - } - - $thesaurus = self::get_thesaurus($sbas_id); - - if($thesaurus && ($tmp = DomDocument::loadXML($thesaurus)) !== false) - self::$_dom_thesaurus[$sbas_id] = $tmp; - else - self::$_dom_thesaurus[$sbas_id] = false; - - return self::$_dom_thesaurus[$sbas_id]; - } - - public static function get_xpath_thesaurus($sbas_id) - { - if(isset(self::$_xpath_thesaurus[$sbas_id])) - { - return self::$_xpath_thesaurus[$sbas_id]; - } - - $DOM_thesaurus = self::get_dom_thesaurus($sbas_id); + $sql = 'LOCK TABLE uids WRITE'; + if ($conn->query($sql)) + { + $sql = "UPDATE uids SET uid=uid+$askfor_n WHERE name='$typeId'"; + if ($conn->query($sql)) + { + $sql = "SELECT uid FROM uids WHERE name='$typeId'"; + if ($result = $conn->query($sql)) + { + if ($row = mysql_fetch_assoc($result)) + $x = ($row["uid"] - $askfor_n) + 1; + mysql_free_result($result); + } + } + $sql = 'UNLOCK TABLES'; + $conn->query($sql); + } + return $x; + } - if($DOM_thesaurus && ($tmp = new DOMXPath( $DOM_thesaurus )) !== false) - self::$_xpath_thesaurus[$sbas_id] = $tmp; - else - self::$_xpath_thesaurus[$sbas_id] = false; - - return self::$_xpath_thesaurus[$sbas_id]; - } - - - public static function get_sxml_thesaurus($sbas_id) - { - - if(isset(self::$_sxml_thesaurus[$sbas_id])) - { - return self::$_sxml_thesaurus[$sbas_id]; - } - - $thesaurus = self::get_thesaurus($sbas_id); - - if($thesaurus && ($tmp = simplexml_load_string($thesaurus)) !== false) - self::$_sxml_thesaurus[$sbas_id] = $tmp; - else - self::$_sxml_thesaurus[$sbas_id] = false; - - return self::$_sxml_thesaurus[$sbas_id]; - } - - - public static function get_thesaurus($sbas_id) - { - $cache_appbox = cache_appbox::getInstance(); - - if(($tmp = $cache_appbox->get('thesaurus_'.$sbas_id)) !== false) - { - self::$_thesaurus[$sbas_id] = $tmp; - return $tmp; - } - - if(isset(self::$_thesaurus[$sbas_id])) - { - return self::$_thesaurus[$sbas_id]; - } - - $thesaurus = false; - $connsbas = connection::getInstance($sbas_id); - $sql = 'SELECT value AS thesaurus FROM pref WHERE prop="thesaurus" LIMIT 1;'; - - if($rs = $connsbas->query($sql)) - { - if($row = $connsbas->fetch_assoc($rs)) - { - $thesaurus = trim($row['thesaurus']); - } - $connsbas->free_result($rs); - } - - self::$_thesaurus[$sbas_id] = $thesaurus; - - if(self::$_thesaurus[$sbas_id]) - $cache_appbox->set('thesaurus_'.$sbas_id,self::$_thesaurus[$sbas_id]); - - return self::$_thesaurus[$sbas_id]; - } - + private function init_data_conn($new_db=false) + { + // just in case + if (is_resource($this->conn)) + { + mysql_close($this->conn); + $this->conn = false; + } - public static function get_structure($sbas_id) + // connect to appbox + require dirname(__FILE__) . '/../../config/connexion.inc'; + + $conn = connection::getInstance(); + + if ($conn) + { + + if (!$new_db) + { + // same as appbox + $this->host = $hostname; + $this->port = $port; + $this->user = $user; + $this->passwd = $password; + } + else + { + $this->host = $new_db['hostname']; + $this->port = $new_db['port']; + $this->user = $new_db['user']; + $this->passwd = $new_db['password']; + } + + $this->conn = mysql_connect($this->host . ":" . $this->port, $this->user, $this->passwd, true); + + mysql_set_charset('utf8', $this->conn); + mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $this->conn); + + if ($this->conn !== false) + return true; + } + return false; + } + + public function setNewStructure($data_template, $path_web, $path_doc, $baseurl) + { + if (is_file($data_template)) + { + $contents = file_get_contents($data_template); + + $baseurl = $baseurl ? p4string::addEndSlash($baseurl) : ''; + + $contents = str_replace( + array("{{dataurl}}", "{{basename}}", "{{datapathweb}}", "{{datapathnoweb}}"), + array($baseurl, $this->dbname, $path_web, $path_doc), + $contents + ); + + $this->structure = $contents; + + $sql = 'UPDATE pref SET value="' . mysql_real_escape_string($this->structure, $this->conn) . '", updated_on=NOW() WHERE prop="structure"'; + if (mysql_query($sql, $this->conn)) + return true; + } + + return false; + } + + public function registerAdmin($usr_id, $bool) + { + $conn = connection::getInstance(); + $sql = 'UPDATE sbasusr SET bas_manage="' . ($bool === true ? '1' : '0') . '" WHERE usr_id = "' . $usr_id . '" AND sbas_id="' . $this->id . '"'; + if ($conn->query($sql)) + return true; + return false; + } + + public function registerAdminStruct($usr_id, $bool) + { + $conn = connection::getInstance(); + $sql = 'UPDATE sbasusr SET bas_modify_struct="' . ($bool === true ? '1' : '0') . '" WHERE usr_id = "' . $usr_id . '" AND sbas_id="' . $this->id . '"'; + if ($conn->query($sql)) + return true; + return false; + } + + public function registerAdminThesaurus($usr_id, $bool) + { + $conn = connection::getInstance(); + $sql = 'UPDATE sbasusr SET bas_modif_th="' . ($bool === true ? '1' : '0') . '" WHERE usr_id = "' . $usr_id . '" AND sbas_id="' . $this->id . '"'; + if ($conn->query($sql)) + return true; + return false; + } + + public function registerPublication($usr_id, $bool) + { + $conn = connection::getInstance(); + $sql = 'UPDATE sbasusr SET bas_chupub="' . ($bool === true ? '1' : '0') . '" WHERE usr_id = "' . $usr_id . '" AND sbas_id="' . $this->id . '"'; + if ($conn->query($sql)) + return true; + return false; + } + + public static function printStatus($name) + { + + $cache_data = cache_appbox::getInstance(); + + if (($tmp = $cache_data->get('status' . $name)) !== false) + return $tmp; + + $filename = GV_RootPath . 'config/status/' . $name; + + $out = ''; + + if (is_file($filename)) + { + $out = file_get_contents($filename); + } + + $cache_data->set('status' . $name, $out); + + return $out; + } + + public static function getPrintLogo($sbas_id) + { + + $cache_data = cache_appbox::getInstance(); + + $out = ''; + if (is_file(($filename = GV_RootPath . 'config/minilogos/logopdf_' . $sbas_id . '.jpg'))) + $out = file_get_contents($filename); + + return $out; + } + + public static function getColls($sbas_id=false) + { + $tbas = array(); + $conn = connection::getInstance(); + + if ($sbas_id !== false) + $sql = "SELECT * FROM sbas s, bas b WHERE s.sbas_id='" . $conn->escape_string($sbas_id) . "' AND s.sbas_id = b.sbas_id AND b.active = '1' ORDER BY s.ord ASC, b.ord ASC"; + else + $sql = "SELECT * FROM sbas s, bas b WHERE s.sbas_id = b.sbas_id AND b.active = '1' ORDER BY s.ord ASC, b.ord ASC"; + + if ($rs = $conn->query($sql)) + { + while ($row = $conn->fetch_assoc($rs)) + { + if (!isset($tbas[$row["sbas_id"]])) + { + $tbas[$row["sbas_id"]] = array('viewname' => (trim($row['viewname']) != '' ? $row['viewname'] : $row['dbname']), 'colls' => array()); + + $connbas = connection::getInstance($row['sbas_id']); + if ($connbas) + { + $sql = "SELECT coll_id, asciiname FROM coll"; + if ($rsbas = $connbas->query($sql)) + { + while ($rowbas = $connbas->fetch_assoc($rsbas)) + { + $colls[$row['sbas_id']][$rowbas["coll_id"]] = $rowbas['asciiname']; + } + $conn->free_result($rsbas); + } + } + } + $tbas[$row["sbas_id"]]['colls'][$row['base_id']] = isset($colls[$row['sbas_id']][$row['server_coll_id']]) ? $colls[$row['sbas_id']][$row['server_coll_id']] : 'unknown name'; + } + $conn->free_result($rs); + } + return($tbas); + } + + public static function get_dom_thesaurus($sbas_id) + { + if (isset(self::$_dom_thesaurus[$sbas_id])) + { + return self::$_dom_thesaurus[$sbas_id]; + } + + $thesaurus = self::get_thesaurus($sbas_id); + + if ($thesaurus && ($tmp = DomDocument::loadXML($thesaurus)) !== false) + self::$_dom_thesaurus[$sbas_id] = $tmp; + else + self::$_dom_thesaurus[$sbas_id] = false; + + return self::$_dom_thesaurus[$sbas_id]; + } + + public static function get_xpath_thesaurus($sbas_id) + { + if (isset(self::$_xpath_thesaurus[$sbas_id])) + { + return self::$_xpath_thesaurus[$sbas_id]; + } + + $DOM_thesaurus = self::get_dom_thesaurus($sbas_id); + + if ($DOM_thesaurus && ($tmp = new phrasea_DOMXPath($DOM_thesaurus)) !== false) + self::$_xpath_thesaurus[$sbas_id] = $tmp; + else + self::$_xpath_thesaurus[$sbas_id] = false; + + return self::$_xpath_thesaurus[$sbas_id]; + } + + public static function get_sxml_thesaurus($sbas_id) + { + + if (isset(self::$_sxml_thesaurus[$sbas_id])) + { + return self::$_sxml_thesaurus[$sbas_id]; + } + + $thesaurus = self::get_thesaurus($sbas_id); + + if ($thesaurus && ($tmp = simplexml_load_string($thesaurus)) !== false) + self::$_sxml_thesaurus[$sbas_id] = $tmp; + else + self::$_sxml_thesaurus[$sbas_id] = false; + + return self::$_sxml_thesaurus[$sbas_id]; + } + + public static function get_thesaurus($sbas_id) + { + $cache_appbox = cache_appbox::getInstance(); + + if (($tmp = $cache_appbox->get('thesaurus_' . $sbas_id)) !== false) + { + self::$_thesaurus[$sbas_id] = $tmp; + return $tmp; + } + + if (isset(self::$_thesaurus[$sbas_id])) + { + return self::$_thesaurus[$sbas_id]; + } + + $thesaurus = false; + $connsbas = connection::getInstance($sbas_id); + $sql = 'SELECT value AS thesaurus FROM pref WHERE prop="thesaurus" LIMIT 1;'; + + if ($rs = $connsbas->query($sql)) + { + if ($row = $connsbas->fetch_assoc($rs)) + { + $thesaurus = trim($row['thesaurus']); + } + $connsbas->free_result($rs); + } + + self::$_thesaurus[$sbas_id] = $thesaurus; + + if (self::$_thesaurus[$sbas_id]) + $cache_appbox->set('thesaurus_' . $sbas_id, self::$_thesaurus[$sbas_id]); + + return self::$_thesaurus[$sbas_id]; + } + + public static function get_structure($sbas_id) + { + $session = session::getInstance(); + $locale = isset($session->locale) ? $session->locale : GV_default_lng; + $basesettings = phrasea::load_settings($locale); + + if (isset($basesettings["bases"][$sbas_id])) + return $basesettings["bases"][$sbas_id]["structure"]; + + return false; + } + + public static function get_dom_structure($sbas_id) + { + if (isset(self::$_dom_structure[$sbas_id])) + { + return self::$_dom_structure[$sbas_id]; + } + + $structure = self::get_structure($sbas_id); + + $dom = new DOMDocument(); + + $dom->standalone = true; + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + + if ($structure && $dom->loadXML($structure) !== false) + self::$_dom_structure[$sbas_id] = $dom; + else + self::$_dom_structure[$sbas_id] = false; + + return self::$_dom_structure[$sbas_id]; + } + + public static function get_sxml_structure($sbas_id) + { + if (isset(self::$_sxml_structure[$sbas_id])) + { + return self::$_sxml_structure[$sbas_id]; + } + + $structure = self::get_structure($sbas_id); + + if ($structure && ($tmp = simplexml_load_string($structure)) !== false) + self::$_sxml_structure[$sbas_id] = $tmp; + else + self::$_sxml_structure[$sbas_id] = false; + + return self::$_sxml_structure[$sbas_id]; + } + + public static function get_xpath_structure($sbas_id) + { + if (isset(self::$_xpath_structure[$sbas_id])) + { + return self::$_xpath_structure[$sbas_id]; + } + + $dom_doc = self::get_dom_structure($sbas_id); + + if ($dom_doc && ($tmp = new DOMXpath($dom_doc)) !== false) + self::$_xpath_structure[$sbas_id] = $tmp; + else + self::$_xpath_structure[$sbas_id] = false; + + return self::$_xpath_structure[$sbas_id]; + } + + public static function get_structure_errors($structure) + { + $sx_structure = simplexml_load_string($structure); + + $subdefgroup = $sx_structure->subdefs[0]; + $AvSubdefs = array(); + + $errors = array(); + + foreach ($subdefgroup as $k => $subdefs) + { + $subdefgroup_name = trim((string) $subdefs->attributes()->name); + + if ($subdefgroup_name == '') + { + $errors[] = _('ERREUR : TOUTES LES BALISES subdefgroup necessitent un attribut name'); + continue; + } + + if (!isset($AvSubdefs[$subdefgroup_name])) + $AvSubdefs[$subdefgroup_name] = array(); + + foreach ($subdefs as $sd) + { + $sd_name = trim(mb_strtolower((string) $sd->attributes()->name)); + $sd_class = trim(mb_strtolower((string) $sd->attributes()->class)); + if ($sd_name == '' || isset($AvSubdefs[$subdefgroup_name][$sd_name])) + { + $errors[] = _('ERREUR : Les name de subdef sont uniques par groupe de subdefs et necessaire'); + continue; + } + if (!in_array($sd_class, array('thumbnail', 'preview', 'document'))) + { + $errors[] = _('ERREUR : La classe de subdef est necessaire et egal a "thumbnail","preview" ou "document"'); + continue; + } + $AvSubdefs[$subdefgroup_name][$sd_name] = $sd; + } + } + + return $errors; + } + + public static function get_subdefs($sbas_id) + { + $sx_struct = self::get_sxml_structure($sbas_id); + + if (!$sx_struct) + return array(); + + $subdefgroup = $sx_struct->subdefs[0]; + + $AvSubdefs = array(); + + foreach ($subdefgroup as $k => $subdefs) + { + $subdefgroup_name = (string) $subdefs->attributes()->name; + + if (!isset($AvSubdefs[$subdefgroup_name])) + $AvSubdefs[$subdefgroup_name] = array(); + + foreach ($subdefs as $sd) + { + $AvSubdefs[$subdefgroup_name][mb_strtolower((string) $sd->attributes()->name)] = $sd; + } + } + + if (!isset($AvSubdefs['flash'])) + $AvSubdefs['flash'] = $AvSubdefs['image']; + if (!isset($AvSubdefs['document'])) + $AvSubdefs['document'] = $AvSubdefs['image']; + + + return $AvSubdefs; + } + +} + +class phrasea_DOMXPath extends DOMXPath +{ + static $r = array(); + function cache_query($xquery, $context_node=NULL, $context_path='') { - $session = session::getInstance(); - $locale = isset($session->locale) ? $session->locale : GV_default_lng; - $basesettings = phrasea::load_settings($locale); - - if(isset($basesettings["bases"][$sbas_id])) - return $basesettings["bases"][$sbas_id]["structure"]; - - return false; + $context_path .= $xquery; + if(!array_key_exists($context_path, self::$r)) + self::$r[$context_path] = $context_node ? parent::query($xquery, $context_node) : parent::query($xquery); + return(self::$r[$context_path]); } - - - public static function get_dom_structure($sbas_id) - { - if(isset(self::$_dom_structure[$sbas_id])) - { - return self::$_dom_structure[$sbas_id]; - } - - $structure = self::get_structure($sbas_id); - - $dom = new DOMDocument(); - - $dom->standalone = true; - $dom->preserveWhiteSpace = false; - $dom->formatOutput = true; - - if($structure && $dom->loadXML($structure) !== false) - self::$_dom_structure[$sbas_id] = $dom; - else - self::$_dom_structure[$sbas_id] = false; - - return self::$_dom_structure[$sbas_id]; - } - - - - public static function get_sxml_structure($sbas_id) - { - if(isset(self::$_sxml_structure[$sbas_id])) - { - return self::$_sxml_structure[$sbas_id]; - } - - $structure = self::get_structure($sbas_id); - - if($structure && ($tmp = simplexml_load_string($structure)) !== false) - self::$_sxml_structure[$sbas_id] = $tmp; - else - self::$_sxml_structure[$sbas_id] = false; - - return self::$_sxml_structure[$sbas_id]; - } - - - public static function get_xpath_structure($sbas_id) - { - if(isset(self::$_xpath_structure[$sbas_id])) - { - return self::$_xpath_structure[$sbas_id]; - } - - $dom_doc = self::get_dom_structure($sbas_id); - - if($dom_doc && ($tmp = new DOMXpath($dom_doc)) !== false) - self::$_xpath_structure[$sbas_id] = $tmp; - else - self::$_xpath_structure[$sbas_id] = false; - - return self::$_xpath_structure[$sbas_id]; - } - - public static function get_structure_errors($structure) - { - $sx_structure = simplexml_load_string($structure); - - $subdefgroup = $sx_structure->subdefs[0]; - $AvSubdefs = array(); - - $errors = array(); - - foreach($subdefgroup as $k=>$subdefs) - { - $subdefgroup_name = trim((string)$subdefs->attributes()->name); - - if($subdefgroup_name == '') - { - $errors[] = _('ERREUR : TOUTES LES BALISES subdefgroup necessitent un attribut name'); - continue; - } - - if(!isset($AvSubdefs[$subdefgroup_name])) - $AvSubdefs[$subdefgroup_name] = array(); - - foreach($subdefs as $sd) - { - $sd_name = trim(mb_strtolower((string)$sd->attributes()->name)); - $sd_class = trim(mb_strtolower((string)$sd->attributes()->class)); - if($sd_name == '' || isset($AvSubdefs[$subdefgroup_name][$sd_name])) - { - $errors[] = _('ERREUR : Les name de subdef sont uniques par groupe de subdefs et necessaire'); - continue; - } - if(!in_array($sd_class,array('thumbnail','preview','document'))) - { - $errors[] = _('ERREUR : La classe de subdef est necessaire et egal a "thumbnail","preview" ou "document"'); - continue; - } - $AvSubdefs[$subdefgroup_name][$sd_name] = $sd; - } - } - - return $errors; - } - - public static function get_subdefs($sbas_id) - { - $sx_struct = self::get_sxml_structure($sbas_id); - - if(!$sx_struct) - return array(); - - $subdefgroup = $sx_struct->subdefs[0]; - - $AvSubdefs = array(); - - foreach($subdefgroup as $k=>$subdefs) - { - $subdefgroup_name = (string)$subdefs->attributes()->name; - - if(!isset($AvSubdefs[$subdefgroup_name])) - $AvSubdefs[$subdefgroup_name] = array(); - - foreach($subdefs as $sd) - { - $AvSubdefs[$subdefgroup_name][mb_strtolower((string)$sd->attributes()->name)] = $sd; - } - } - - if(!isset($AvSubdefs['flash'])) - $AvSubdefs['flash'] = $AvSubdefs['image']; - if(!isset($AvSubdefs['document'])) - $AvSubdefs['document'] = $AvSubdefs['image']; - - - return $AvSubdefs; - } -} \ No newline at end of file +} + diff --git a/lib/classes/export.class.php b/lib/classes/export.class.php index 377ade17fe..83d4c2aa87 100644 --- a/lib/classes/export.class.php +++ b/lib/classes/export.class.php @@ -699,7 +699,19 @@ class export if(GV_modxsendfile) { - $file_xaccel = str_replace(array(GV_X_Accel_Redirect, GV_RootPath.'tmp/download/'), array('/'.GV_X_Accel_Redirect_mount_point.'/', '/download/'), $file); + $file_xaccel = str_replace( + array( + GV_X_Accel_Redirect, + GV_RootPath . 'tmp/download/', + GV_RootPath . 'tmp/lazaret/' + ) + , array( + '/' . GV_X_Accel_Redirect_mount_point . '/', + '/download/', + '/lazaret/' + ) + , $file + ); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); diff --git a/lib/classes/mail.class.php b/lib/classes/mail.class.php index 089f45d8aa..c9057696a7 100644 --- a/lib/classes/mail.class.php +++ b/lib/classes/mail.class.php @@ -2,266 +2,273 @@ class mail { - - public static function mail_test($email) - { - $from = array('email'=>GV_defaulmailsenderaddr,'name'=>GV_defaulmailsenderaddr); - - $subject = _('mail:: test d\'envoi d\'email'); - - $message = sprintf(_('Ce mail est un test d\'envoi de mail depuis %s'),GV_ServerName); - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $message, $to, $from); - } - - public static function send_validation_results($email,$subject,$from, $message) - { - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $message, $to, $from); - } - - public static function hack_alert($email, $body) - { - $subject = 'Hack on '.GV_homeTitle; - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function ftp_sent($email, $subject, $body) - { - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function ftp_receive($email, $body) - { - $subject = _("task::ftp:Someone has sent some files onto FTP server"); - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function send_documents($email, $url,$from, $message='',$accuse) - { - $subject = _('export::vous avez recu des documents'); - - $body = '
'._('Vous avez recu des documents, vous pourrez les telecharger a ladresse suivante ')."
\n"; - $body .= "".$url."\n"; - - if($message != '') - { - $body .= "
---------------------------------------------------
\n".$message; - } - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to, $from, array(), $accuse); - } - - public static function forgot_passord($email, $login, $url) - { - $subject = _('login:: Forgot your password') ; // Registration order on . - - $body = "
"._('login:: Quelqu\'un a demande a reinitialiser le mode passe correspondant au login suivant : ') . "
\n\n" . $login . "
\n\n"; - $body .= "
"._('login:: Visitez le lien suivant et suivez les instructions pour continuer, sinon ignorez cet email et il ne se passera rien') . "
\n\n" ; - $body .= "
".''.$url.''."
\n" ; - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - - public static function register_confirm($email, $accept, $deny) - { - - $subject = sprintf(_('login::register:email: Votre compte %s'), GV_homeTitle); - - $body = '
'._('login::register:email: Voici un compte rendu du traitement de vos demandes d\'acces :')."
\n"; - - if($accept != '') - { - $body .= "
\n
"._('login::register:email: Vous avez ete accepte sur les collections suivantes : ')."
\n\n"; - } - if($deny != '') - { - $body .= "
\n
"._('login::register:email: Vous avez ete refuse sur les collections suivantes : ')."
\n\n"; - } - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - - public static function register_user($email, $auto, $others) - { - - $subject = sprintf(_('login::register:email: Votre compte %s'),GV_homeTitle); - - - $body = "
"._('login::register:Votre inscription a ete prise en compte')."
\n"; - - if($auto != '') - { - $body .= "
\n
"._('login::register: vous avez des a present acces aux collections suivantes : ')."
\n\n"; - } - - if($others != '') - { - $body .= "
\n
"._('login::register: vos demandes concernat les collections suivantes sont sujettes a approbation d\'un administrateur')."
\n\n"; - $body .= "
\n
"._('login::register : vous serez avertis par email lorsque vos demandes seront traitees')."
\n"; - } - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function reset_email($email,$usr_id) - { - $date = new DateTime('1 day'); - $date = phraseadate::format_mysql($date); - $token = random::getUrlToken('email',$usr_id,$date,$email); - - $url = GV_ServerName.'login/reset-email.php?token='.$token; - - $subject = _('login::register: sujet email : confirmation de votre adresse email'); - - $body = "
"._('admin::compte-utilisateur: email changement de mot d\'email Bonjour, nous avons bien recu votre demande de changement d\'adresse e-mail. Pour la confirmer, veuillez suivre le lien qui suit. SI vous recevez ce mail sans l\'avoir sollicite, merci de le detruire et de l\'ignorer.')."
\n"; - $body .= '
'.$url.'
\n'; - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function mail_confirm_registered($email) - { - $subject = _('login::register: sujet email : confirmation de votre adresse email'); - - $body = "
"._('login::register: merci d\'avoir confirme votre adresse email')."
\n"; - $body .= "
"._('login::register: vous pouvez maintenant vous connecter a l\'adresse suivante : ')."
\n"; - $body .= "
".GV_ServerName."
\n"; - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function mail_confirm_unregistered($email, $others) - { - - $subject = _('login::register: sujet email : confirmation de votre adresse email'); - - $body = "
"._('login::register: merci d\'avoir confirme votre adresse email')."
\n"; - $body .= "
\n
"._('login::register: vous devez attendre la confirmation d\'un administrateur ; vos demandes sur les collections suivantes sont toujours en attente : ')."
\n\n"; - $body .= "
\n
"._('login::register : vous serez avertis par email lorsque vos demandes seront traitees')."
\n"; - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - public static function mail_confirmation($email,$usr_id) - { - - $expire = new DateTime('+3 days'); - $expire = phraseadate::format_mysql($expire); - $token = random::getUrlToken('password',$usr_id,$expire,$email); - - $subject = _('login::register: sujet email : confirmation de votre adresse email'); - - $body = "
"._('login::register: email confirmation email Pour valider votre inscription a la base de donnees, merci de confirmer votre e-mail en suivant le lien ci-dessous.')."
\n"; - $body .= "
\n
".GV_ServerName."register-confirm=".$token."
\n"; - - $to = array('email'=>$email,'name'=>$email); - - return self::send_mail($subject, $body, $to); - } - - - public static function send_mail($subject,$body,$to,$from=false,$files=array(),$reading_confirm_to=false) - { - require_once(GV_RootPath.'lib/PHPMailer_v5.1/class.phpmailer.php'); - - if(!isset($to['email']) || !PHPMailer::ValidateAddress($to['email'])) - return false; - - $mail = new PHPMailer(); - - $body = eregi_replace("[\]",'',$body); - - $body .= "



\n\n\n\n"; - $body .= '
'._('phraseanet::signature automatique des notifications par mail, infos a l\'url suivante')."
\n"; - $body .= '
'.GV_ServerName."
\n"; - $body = ''.$body.''; - - try { - $mail->CharSet = 'utf-8'; - $mail->Encoding = 'base64';//'quoted-printable'; - - if(GV_smtp) - { - $mail->IsSMTP(); - if(GV_smtp_host != '') - $mail->Host = GV_smtp_host; -// $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) - if(GV_smtp_auth) - { - $mail->SMTPAuth = true; - - if(GV_smtp_secure === true) - { - $mail->SMTPSecure = "ssl"; - } - $mail->Host = GV_smtp_host; - $mail->Port = GV_smtp_port; - $mail->Username = GV_smtp_user; - $mail->Password = GV_smtp_password; - } - } - if($from && trim($from['email']) != '') - $mail->AddReplyTo($from['email'],$from['name']); - - $mail->AddAddress($to['email'], $to['name']); - - $mail->SetFrom(GV_defaulmailsenderaddr, GV_homeTitle); - - $mail->Subject = $subject; - - $mail->AltBody = html_entity_decode(strip_tags($body),ENT_QUOTES,'UTF-8'); - - if($reading_confirm_to) - { - $mail->ConfirmReadingTo = $reading_confirm_to; - } - - $mail->MsgHTML(p4string::cleanTags($body)); - - foreach($files as $f) - { - $mail->AddAttachment($f); // attachment - } - - $mail->Send(); - return true; - } - catch (phpmailerException $e) - { - return $e->errorMessage(); - } - catch (Exception $e) - { - return $e->getMessage(); - } - } + public static function mail_test($email) + { + $from = array('email' => GV_defaulmailsenderaddr, 'name' => GV_defaulmailsenderaddr); + + $subject = _('mail:: test d\'envoi d\'email'); + + $message = sprintf(_('Ce mail est un test d\'envoi de mail depuis %s'), GV_ServerName); + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $message, $to, $from); + } + + public static function send_validation_results($email, $subject, $from, $message) + { + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $message, $to, $from); + } + + public static function hack_alert($email, $body) + { + $subject = 'Hack on ' . GV_homeTitle; + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function ftp_sent($email, $subject, $body) + { + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function ftp_receive($email, $body) + { + $subject = _("task::ftp:Someone has sent some files onto FTP server"); + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function send_documents($email, $url, $from, $endate_obj, $message='', $accuse) + { + $subject = _('export::vous avez recu des documents'); + + $body = '
' . _('Vous avez recu des documents, vous pourrez les telecharger a ladresse suivante ') . "
\n"; + $body .= "" . $url . "\n"; + + $body .= '
' . + sprintf( + _('Attention, ce lien lien est valable jusqu\'au %s'), + phraseadate::getDate($endate_obj) . ' ' . phraseadate::getTime($endate_obj) + ) + . '
'; + + + if ($message != '') + { + $body .= "
---------------------------------------------------
\n" . $message; + } + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to, $from, array(), $accuse); + } + + public static function forgot_passord($email, $login, $url) + { + $subject = _('login:: Forgot your password'); // Registration order on . + + $body = "
" . _('login:: Quelqu\'un a demande a reinitialiser le mode passe correspondant au login suivant : ') . "
\n\n" . $login . "
\n\n"; + $body .= "
" . _('login:: Visitez le lien suivant et suivez les instructions pour continuer, sinon ignorez cet email et il ne se passera rien') . "
\n\n"; + $body .= "
" . '' . $url . '' . "
\n"; + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function register_confirm($email, $accept, $deny) + { + + $subject = sprintf(_('login::register:email: Votre compte %s'), GV_homeTitle); + + $body = '
' . _('login::register:email: Voici un compte rendu du traitement de vos demandes d\'acces :') . "
\n"; + + if ($accept != '') + { + $body .= "
\n
" . _('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . "
\n\n"; + } + if ($deny != '') + { + $body .= "
\n
" . _('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . "
\n\n"; + } + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function register_user($email, $auto, $others) + { + + $subject = sprintf(_('login::register:email: Votre compte %s'), GV_homeTitle); + + + $body = "
" . _('login::register:Votre inscription a ete prise en compte') . "
\n"; + + if ($auto != '') + { + $body .= "
\n
" . _('login::register: vous avez des a present acces aux collections suivantes : ') . "
\n\n"; + } + + if ($others != '') + { + $body .= "
\n
" . _('login::register: vos demandes concernat les collections suivantes sont sujettes a approbation d\'un administrateur') . "
\n\n"; + $body .= "
\n
" . _('login::register : vous serez avertis par email lorsque vos demandes seront traitees') . "
\n"; + } + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function reset_email($email, $usr_id) + { + $date = new DateTime('1 day'); + $date = phraseadate::format_mysql($date); + $token = random::getUrlToken('email', $usr_id, $date, $email); + + $url = GV_ServerName . 'login/reset-email.php?token=' . $token; + + $subject = _('login::register: sujet email : confirmation de votre adresse email'); + + $body = "
" . _('admin::compte-utilisateur: email changement de mot d\'email Bonjour, nous avons bien recu votre demande de changement d\'adresse e-mail. Pour la confirmer, veuillez suivre le lien qui suit. SI vous recevez ce mail sans l\'avoir sollicite, merci de le detruire et de l\'ignorer.') . "
\n"; + $body .= '
' . $url . '
\n'; + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function mail_confirm_registered($email) + { + $subject = _('login::register: sujet email : confirmation de votre adresse email'); + + $body = "
" . _('login::register: merci d\'avoir confirme votre adresse email') . "
\n"; + $body .= "
" . _('login::register: vous pouvez maintenant vous connecter a l\'adresse suivante : ') . "
\n"; + $body .= "
" . GV_ServerName . "
\n"; + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function mail_confirm_unregistered($email, $others) + { + + $subject = _('login::register: sujet email : confirmation de votre adresse email'); + + $body = "
" . _('login::register: merci d\'avoir confirme votre adresse email') . "
\n"; + $body .= "
\n
" . _('login::register: vous devez attendre la confirmation d\'un administrateur ; vos demandes sur les collections suivantes sont toujours en attente : ') . "
\n\n"; + $body .= "
\n
" . _('login::register : vous serez avertis par email lorsque vos demandes seront traitees') . "
\n"; + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function mail_confirmation($email, $usr_id) + { + + $expire = new DateTime('+3 days'); + $expire = phraseadate::format_mysql($expire); + $token = random::getUrlToken('password', $usr_id, $expire, $email); + + $subject = _('login::register: sujet email : confirmation de votre adresse email'); + + $body = "
" . _('login::register: email confirmation email Pour valider votre inscription a la base de donnees, merci de confirmer votre e-mail en suivant le lien ci-dessous.') . "
\n"; + $body .= "
\n
" . GV_ServerName . "register-confirm=" . $token . "
\n"; + + $to = array('email' => $email, 'name' => $email); + + return self::send_mail($subject, $body, $to); + } + + public static function send_mail($subject, $body, $to, $from=false, $files=array(), $reading_confirm_to=false) + { + require_once(GV_RootPath . 'lib/PHPMailer_v5.1/class.phpmailer.php'); + + if (!isset($to['email']) || !PHPMailer::ValidateAddress($to['email'])) + return false; + + $mail = new PHPMailer(); + + $body = eregi_replace("[\]", '', $body); + + $body .= "



\n\n\n\n"; + $body .= '
' . _('phraseanet::signature automatique des notifications par mail, infos a l\'url suivante') . "
\n"; + $body .= '
' . GV_ServerName . "
\n"; + $body = '' . $body . ''; + + try + { + $mail->CharSet = 'utf-8'; + $mail->Encoding = 'base64'; //'quoted-printable'; + + if (GV_smtp) + { + $mail->IsSMTP(); + if (GV_smtp_host != '') + $mail->Host = GV_smtp_host; +// $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) + if (GV_smtp_auth) + { + $mail->SMTPAuth = true; + + if (GV_smtp_secure === true) + { + $mail->SMTPSecure = "ssl"; + } + $mail->Host = GV_smtp_host; + $mail->Port = GV_smtp_port; + $mail->Username = GV_smtp_user; + $mail->Password = GV_smtp_password; + } + } + + if ($from && trim($from['email']) != '') + $mail->AddReplyTo($from['email'], $from['name']); + + $mail->AddAddress($to['email'], $to['name']); + + $mail->SetFrom(GV_defaulmailsenderaddr, GV_homeTitle); + + $mail->Subject = $subject; + + $mail->AltBody = html_entity_decode(strip_tags($body), ENT_QUOTES, 'UTF-8'); + + if ($reading_confirm_to) + { + $mail->ConfirmReadingTo = $reading_confirm_to; + } + + $mail->MsgHTML(p4string::cleanTags($body)); + + foreach ($files as $f) + { + $mail->AddAttachment($f); // attachment + } + + $mail->Send(); + return true; + } + catch (phpmailerException $e) + { + return $e->errorMessage(); + } + catch (Exception $e) + { + return $e->getMessage(); + } + } + } \ No newline at end of file diff --git a/lib/classes/phraseadate.class.php b/lib/classes/phraseadate.class.php index 37b1012f6d..bb4ca961a0 100644 --- a/lib/classes/phraseadate.class.php +++ b/lib/classes/phraseadate.class.php @@ -37,7 +37,7 @@ class phraseadate $diff = $compareTo->format('U') - $date->format('U'); $dayDiff = floor($diff / 86400); - if(is_nan($dayDiff) || $dayDiff < 0) { + if(is_nan($dayDiff)) { return ''; } diff --git a/lib/classes/query.class.php b/lib/classes/query.class.php index 02bfef8722..4813f2b9c8 100644 --- a/lib/classes/query.class.php +++ b/lib/classes/query.class.php @@ -247,7 +247,6 @@ class query $dstatus = status::getDisplayStatus(); - $array_icons = array( 'flash' => '', 'document' => '', @@ -308,6 +307,7 @@ class query $base_id = $data["base_id"]; $thumbnail = answer::getThumbnail($session->ses_id, $data["base_id"], $data["record_id"],GV_zommPrev_rollover_clientAnswer); + if($thumbnail['sha256']) $rsScreen[$irec]['sha256'] = $thumbnail['sha256']; @@ -319,6 +319,7 @@ class query $exifinfos = answer::format_infos($data['xml'], $sbas_id, $data["record_id"],$thumbnail['type']); $captions = answer::format_caption($base_id, $data["record_id"],$data['xml']); } + diff --git a/lib/clientUtils.php b/lib/clientUtils.php index aff063ddfc..01f5bc8073 100644 --- a/lib/clientUtils.php +++ b/lib/clientUtils.php @@ -452,7 +452,8 @@ function getPreviewWindow($usr,$ses,$lng,$env,$pos,$contId,$roll) $docType = isset($sdMain['document'])?$sdMain['document']['type']:'unknown'; $prev = answer::get_preview($bas,$rec,$isFullyPublic); - + + $preview_html = $prev['html']; $preview = $prev['preview']; $flashcontent = $prev['flashcontent']; $width = $prev['width']; @@ -678,6 +679,7 @@ function getPreviewWindow($usr,$ses,$lng,$env,$pos,$contId,$roll) return p4string::jsonencode(array( "prev"=>$preview + ,"prev_html"=>$preview_html ,"flashcontent"=>$flashcontent ,"desc"=>p4string::entitydecode($caption) ,"width"=>$width diff --git a/lib/conf.d/data_templates/en-simple.xml b/lib/conf.d/data_templates/en-simple.xml index 67dbb6a1b2..1bc8895251 100644 --- a/lib/conf.d/data_templates/en-simple.xml +++ b/lib/conf.d/data_templates/en-simple.xml @@ -1,8 +1,8 @@ - {{datapathnoweb}}{{basename}}/documents + {{datapathnoweb}}{{basename}}/documents - + {{datapathnoweb}}{{basename}}/subdefs @@ -13,9 +13,9 @@ 75 yes - image - - + image + + {{datapathweb}}{{basename}}/subdefs @@ -25,10 +25,10 @@ yes 75 no - image + image {{dataurl}}{{basename}}/subdefs - - + + @@ -36,171 +36,187 @@ {{datapathnoweb}}{{basename}}/subdefs 800 - video + video yes faac libx264 1000 - 8 + 8 15 - - + + {{datapathweb}}{{basename}}/subdefs 200 - gif - 1 + gif + 1 no {{dataurl}}/{{basename}}/subdefs - - + + {{datapathweb}}{{basename}}/subdefs 200 - image + image no {{dataurl}}{{basename}}/subdefs - - + + {{datapathnoweb}}{{basename}}/subdefs - audio + audio yes - - + + {{datapathweb}}{{basename}}/subdefs - image + image no {{dataurl}}{{basename}}/subdefs - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - + + + + + + + + + + + - - Online - + + Online + - - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
- - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
- - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
- - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
\ No newline at end of file diff --git a/lib/conf.d/data_templates/fr-simple.xml b/lib/conf.d/data_templates/fr-simple.xml index 0f27deb360..cb65cf671b 100755 --- a/lib/conf.d/data_templates/fr-simple.xml +++ b/lib/conf.d/data_templates/fr-simple.xml @@ -1,208 +1,224 @@ - {{datapathnoweb}}{{basename}}/documents - - - - {{datapathnoweb}}{{basename}}/subdefs - 800 - resample - 72 - no - 75 - yes - - image - - - - - {{datapathweb}}{{basename}}/subdefs - 200 - resample - 72 - yes - 75 - no - image - {{dataurl}}{{basename}}/subdefs - - - - + {{datapathnoweb}}{{basename}}/documents + + + + {{datapathnoweb}}{{basename}}/subdefs + 800 + resample + 72 + no + 75 + yes + + image + + + + + {{datapathweb}}{{basename}}/subdefs + 200 + resample + 72 + yes + 75 + no + image + {{dataurl}}{{basename}}/subdefs + + + + - - - {{datapathnoweb}}{{basename}}/subdefs - 800 - video - yes - - faac - libx264 - 1000 - 8 - 15 - - - - - {{datapathweb}}{{basename}}/subdefs - 200 - gif - 1 - no - {{dataurl}}/{{basename}}/subdefs - - - - - {{datapathweb}}{{basename}}/subdefs - 200 - image - no - {{dataurl}}{{basename}}/subdefs - - - - + + + {{datapathnoweb}}{{basename}}/subdefs + 800 + video + yes + + faac + libx264 + 1000 + 8 + 15 + + + + + {{datapathweb}}{{basename}}/subdefs + 200 + gif + 1 + no + {{dataurl}}/{{basename}}/subdefs + + + + + {{datapathweb}}{{basename}}/subdefs + 200 + image + no + {{dataurl}}{{basename}}/subdefs + + + + - - - {{datapathnoweb}}{{basename}}/subdefs - audio - yes - - - - - - {{datapathweb}}{{basename}}/subdefs - image - no - {{dataurl}}{{basename}}/subdefs - - - - + + + {{datapathnoweb}}{{basename}}/subdefs + audio + yes + + + + + + {{datapathweb}}{{basename}}/subdefs + image + no + {{dataurl}}{{basename}}/subdefs + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - + + + + + + + + + + + - - Online - + + Online + - - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
- - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
- - - - - :
-
-
-
- - - - - :
-
-
-
+ + + + + + + : + +
+
+
+
+ + + + + + + : + +
+
+
+
\ No newline at end of file diff --git a/lib/index_utils2.php b/lib/index_utils2.php index 4d3c5eb3ad..30760df40e 100644 --- a/lib/index_utils2.php +++ b/lib/index_utils2.php @@ -1849,7 +1849,7 @@ function make1subdef($infile, $sd, $physdpath, $infos) // attention, au cas ou il y aurait des espaces dans le path, il faut des quotes // windows n'accepte pas les simple quotes // pour mac les quotes pour les noms de fichiers sont indispensables car si il y a un espace -> ca plante - $array = array('application/pdf','image/psd','image/vnd.adobe.photoshop','image/photoshop','image/ai','image/illustrator','image/vnd.adobe.illustrator'); + $array = array('image/tiff', 'application/pdf','image/psd','image/vnd.adobe.photoshop','image/photoshop','image/ai','image/illustrator','image/vnd.adobe.illustrator'); if( in_array($infos['mime'], $array ) ) $cmd .= ' "'.$infile .'[0]" "'. $outfile .'"'; else diff --git a/templates/web/common/menubar.twig b/templates/web/common/menubar.twig index 757ad10b91..fedc2af53e 100644 --- a/templates/web/common/menubar.twig +++ b/templates/web/common/menubar.twig @@ -46,7 +46,7 @@ {% endif %} {# MODULE #} - {% if module == "validation" %} + {% if module == "lightbox" %} {% trans 'admin::monitor: module validation' %} {% else %} {% trans 'Aucun document dans la quarantaine actuellement' %} {% endif %} + \ No newline at end of file diff --git a/www/admin/databases.php b/www/admin/databases.php index d6f9211cde..e8abbae21c 100644 --- a/www/admin/databases.php +++ b/www/admin/databases.php @@ -135,15 +135,14 @@ if($request->has_post_datas() && $user->is_admin === true) } } } - elseif($parm['mount_base'] && $parm['new_hostname'] && $parm['new_port'] && $parm['new_user'] - && $parm['new_password'] && $parm['new_dbname']) + elseif($parm['mount_base']) { if(!$parm['new_settings'] && $parm['new_dbname']) { if(p4string::hasAccent($parm['new_dbname'])) $error['new_dbname'] = 'No special chars in dbname'; - + if(count($error) === 0) { if( ($base = new databox()) !== false ) @@ -160,9 +159,8 @@ if($request->has_post_datas() && $user->is_admin === true) } } elseif($parm['new_settings'] && $parm['new_hostname'] && $parm['new_port'] && $parm['new_user'] - && $parm['new_password'] && $parm['new_dbname'] && $parm['new_data_template']) + && $parm['new_password'] && $parm['new_dbname']) { - if(p4string::hasAccent($parm['new_dbname'])) $error['new_dbname'] = 'No special chars in dbname'; @@ -170,7 +168,7 @@ if($request->has_post_datas() && $user->is_admin === true) { if( ($base = new databox(false,$parm['new_hostname'],$parm['new_port'],$parm['new_user'],$parm['new_password'])) !== false ) { - if($base->mount($parm['new_dbname'])) + if($base->mount($parm['new_dbname'], $usr_id)) { $sbas_id = $base->save($usr_id); @@ -181,12 +179,12 @@ if($request->has_post_datas() && $user->is_admin === true) $base->registerAdminThesaurus($usr_id, true); $base->registerPublication($usr_id, true); $mountBase = true; - } - } - } - } - } - } + } + } + } + } + } + } } diff --git a/www/admin/structure.php b/www/admin/structure.php index 57fb042c94..8838248970 100644 --- a/www/admin/structure.php +++ b/www/admin/structure.php @@ -92,19 +92,30 @@ if($connbas) if($parm["act"]=="CHGSTRUCTURE") { $errors = databox::get_structure_errors($parm["str"]); - if(count($errors) == 0 && $domst = @DOMDocument::loadXML($parm["str"])) // simplexml_load_string($parm["str"])) + if(count($errors) == 0) { - $domst->documentElement->setAttribute("modification_date", $now = date("YmdHis")); - - $sql = "UPDATE pref SET value='" . $conn->escape_string($parm["str"] = $domst->saveXML()) . "', updated_on='" . $now . "' WHERE prop='structure'" ; - $connbas->query($sql); - - $cache_appbox = cache_appbox::getInstance(); - $cache_appbox->delete('list_bases'); - - cache_databox::update($parm["p0"],'structure'); + $domst = new DOMDocument('1.0', 'UTF-8'); + $domst->preserveWhiteSpace = false; + $domst->formatOutput = true; + if(@$domst->loadXML($parm["str"])) + { + $domst->documentElement->setAttribute("modification_date", $now = date("YmdHis")); + + $sql = "UPDATE pref SET value='" . $conn->escape_string($parm["str"] = $domst->saveXML()) . "', updated_on='" . $now . "' WHERE prop='structure'" ; + $connbas->query($sql); + + $cache_appbox = cache_appbox::getInstance(); + $cache_appbox->delete('list_bases'); + + cache_databox::update($parm["p0"],'structure'); + } + else + { + $errors[] = "Error loadXML(structure)"; + } } - else + + if(count($errors) != 0) { $msg .= p4string::MakeString(_('admin::base: xml invalide, les changements ne seront pas appliques'), 'js') . "" ; $loadit = false; diff --git a/www/client/index.php b/www/client/index.php index e95d11d596..5ebba40c27 100644 --- a/www/client/index.php +++ b/www/client/index.php @@ -662,7 +662,7 @@ if($cssfile) - + + '; break; case 'video': - $embed = '
'; + $embed = '
'; break; case 'document': $embed = ' diff --git a/www/include/sendmailpage.php b/www/include/sendmailpage.php index d40b508185..4729550f2b 100644 --- a/www/include/sendmailpage.php +++ b/www/include/sendmailpage.php @@ -52,7 +52,8 @@ $list = $download->prepare_export($parm['obj'], $titre); $list['export_name'] = $exportname.'.zip'; -$endDate = phraseadate::format_mysql(new DateTime('+1 day')); +$endate_obj = new DateTime('+1 day'); +$endDate = phraseadate::format_mysql($endate_obj); $token = random::getUrlToken('download',false,$endDate,serialize($list)); @@ -75,7 +76,7 @@ if($parm['reading_confirm'] == '1') foreach($dest as $email) { - if(($result = mail::send_documents(trim($email), $url,$from, $parm["textmail"], $reading_confirm_to))!==true) + if(($result = mail::send_documents(trim($email), $url,$from, $endate_obj, $parm["textmail"], $reading_confirm_to))!==true) $res[] = $email; } diff --git a/www/lightbox/validator.php b/www/lightbox/validator.php index 8e7a5ef7a9..90a7ca23ce 100644 --- a/www/lightbox/validator.php +++ b/www/lightbox/validator.php @@ -51,7 +51,7 @@ try 'baskets_collection' => $basket_collection, 'basket' => $basket, 'local_title' => strip_tags($basket->name), - 'module' => 'validation', + 'module' => 'lightbox', 'module_name' => _('admin::monitor: module validation') ) ); diff --git a/www/login/homepubli.php b/www/login/homepubli.php index cf3a08e163..93576526c8 100644 --- a/www/login/homepubli.php +++ b/www/login/homepubli.php @@ -26,10 +26,10 @@ $item = $defaultchannel->appendChild($defaultdom->createElement('item')); $title = $item->appendChild($defaultdom->createElement('title')); $title->appendChild($defaultdom->createTextNode(GV_homeTitle)); -if(file_exists(GV_RootPath.'config/home.jpg')) +if(file_exists(GV_RootPath.'www/custom/home.jpg')) { - $pathPic = GV_RootPath.'config/home.jpg'; - $urlPic = '/config/home.jpg'; + $pathPic = GV_RootPath.'www/custom/home.jpg'; + $urlPic = '/custom/home.jpg'; } else { diff --git a/www/prod/answer.php b/www/prod/answer.php index a0cde382e3..c242421e1f 100644 --- a/www/prod/answer.php +++ b/www/prod/answer.php @@ -1,233 +1,233 @@ get_parms("bas", "qry", "pag" - , "sel", "ord" - , "search_type", "recordtype", "status", "fields", "datemin", "datemax", "datefield"); +if (!isset($parm)) + $parm = $request->get_parms("bas", "qry", "pag" + , "sel", "ord" + , "search_type", "recordtype", "status", "fields", "datemin", "datemax", "datefield"); - -if(isset($session->usr_id) && isset($session->ses_id)) + +if (isset($session->usr_id) && isset($session->ses_id)) { - $ses_id = $session->ses_id; - $usr_id = $session->usr_id; - if(!($ph_session = phrasea_open_session((int)$ses_id, $usr_id))) - { - header("Location: /login/?err=no-session"); - exit(); - } + $ses_id = $session->ses_id; + $usr_id = $session->usr_id; + if (!($ph_session = phrasea_open_session((int) $ses_id, $usr_id))) + { + header("Location: /login/?err=no-session"); + exit(); + } } else { - $request = httpRequest::getInstance(); - if($request->is_ajax()) - { - echo _('Votre session est expiree, veuillez vous reconnecter'); - } - else - { - header("Location: /login/"); - } - exit(); + $request = httpRequest::getInstance(); + if ($request->is_ajax()) + { + echo _('Votre session est expiree, veuillez vous reconnecter'); + } + else + { + header("Location: /login/"); + } + exit(); } - -if(!($ph_session = phrasea_open_session($ses_id,$usr_id))) + +if (!($ph_session = phrasea_open_session($ses_id, $usr_id))) { - die(); + die(); } -if($parm["ord"]===NULL) - $parm["ord"] = PHRASEA_ORDER_DESC; +if ($parm["ord"] === NULL) + $parm["ord"] = PHRASEA_ORDER_DESC; else - $parm["ord"] = (int)$parm["ord"]; - -$parm['sel'] = explode(';',$parm['sel']); + $parm["ord"] = (int) $parm["ord"]; -if(!$parm['bas']) - $parm['bas'] = array(); +$parm['sel'] = explode(';', $parm['sel']); -if(!$parm["pag"]===NULL) - $parm["pag"] = "0"; - -if(trim($parm["qry"])==='') - $parm["qry"] = "all"; +if (!$parm['bas']) + $parm['bas'] = array(); + +if (!$parm["pag"] === NULL) + $parm["pag"] = "0"; + +if (trim($parm["qry"]) === '') + $parm["qry"] = "all"; $mod = user::getPrefs('view'); $options = array( - 'type' => $parm['search_type'], - 'bases' => $parm['bas'], - 'champs' => $parm['fields'], - 'status' => $parm['status'], - 'date' => array( - 'minbound'=>$parm['datemin'], - 'maxbound'=>$parm['datemax'], - 'field'=>explode('|',$parm['datefield']) - ) + 'type' => $parm['search_type'], + 'bases' => $parm['bas'], + 'champs' => $parm['fields'], + 'status' => $parm['status'], + 'date' => array( + 'minbound' => $parm['datemin'], + 'maxbound' => $parm['datemax'], + 'field' => explode('|', $parm['datefield']) + ) ); -if($parm['recordtype'] != '' && in_array($parm['recordtype'],array('image','video','audio','document','flash'))) +if ($parm['recordtype'] != '' && in_array($parm['recordtype'], array('image', 'video', 'audio', 'document', 'flash'))) { - $parm['qry'] .= ' AND recordtype='.$parm['recordtype']; + $parm['qry'] .= ' AND recordtype=' . $parm['recordtype']; } $query = new query($options); -$result = $query->results($parm['qry'], $parm["pag"]);//$parm['search_type'], + +$result = $query->results($parm['qry'], $parm["pag"]); //$parm['search_type'], $proposals = trim($parm['pag']) === '' ? $query->proposals() : false; - $npages = $result['pages']; $page = $result['current_page']; -$string =''; +$string = ''; - if($npages>1) - { - - $d2top = ($npages - $page); - $d2bottom = $page; - - if(min($d2top,$d2bottom) < 4) - { - if($d2bottom < 4) - { - for($i=1;($i<=4 && (($i<=$npages)===true));$i++) - { - if($i == $page) - $string .= ''; - else - $string .= "".$i.""; - } - if($npages >4) - $string .= ">>"; - } - else - { - $start = $npages-4; - if(($start)>0) - $string .= "<<"; - else - $start = 1; - for($i=($start);$i<=$npages;$i++) - { - if($i == $page) - $string .= ''; - else - $string .= "".$i.""; - } - } - } - else - { - $string .= "<<"; - - for($i=($page-2);$i<=($page+2);$i++) - { - if($i == $page) - $string .= ''; - else - $string .= "".$i.""; - } - - $string .= ">>"; - - } - - - - } - $string .= '
'; - - - $explain = $result['explain']; - - $infoResult = ' | '.sprintf(_('reponses:: %d reponses'),$session->prod['query']['nba']).' | '.sprintf(_('reponses:: %s documents selectionnes'),''); +if ($npages > 1) +{ - echo ""; - echo ""; - - $rsScreen = $result['result']; - - if(count($rsScreen)>0) - { - if($mod == 'thumbs') - require("answergrid.php"); - else - require("answerlist.php"); - } - else - { - echo '
'; - phrasea::getHome('HELP','prod'); - echo '
'; - } - + $d2top = ($npages - $page); + $d2bottom = $page; + + if (min($d2top, $d2bottom) < 4) + { + if ($d2bottom < 4) + { + for ($i = 1; ($i <= 4 && (($i <= $npages) === true)); $i++) + { + if ($i == $page) + $string .= ''; + else + $string .= "" . $i . ""; + } + if ($npages > 4) + $string .= ">>"; + } + else + { + $start = $npages - 4; + if (($start) > 0) + $string .= "<<"; + else + $start = 1; + for ($i = ($start); $i <= $npages; $i++) + { + if ($i == $page) + $string .= ''; + else + $string .= "" . $i . ""; + } + } + } + else + { + $string .= "<<"; + + for ($i = ($page - 2); $i <= ($page + 2); $i++) + { + if ($i == $page) + $string .= ''; + else + $string .= "" . $i . ""; + } + + $string .= ">>"; + } +} +$string .= '
'; + +$explain = $result['explain']; + +$infoResult = ' | ' . sprintf(_('reponses:: %d reponses'), $session->prod['query']['nba']) . ' | ' . sprintf(_('reponses:: %s documents selectionnes'), ''); + +echo ""; +echo ""; + +$rsScreen = $result['result']; + +if (count($rsScreen) > 0) +{ + if ($mod == 'thumbs') + require("answergrid.php"); + else + require("answerlist.php"); +} +else +{ + echo '
'; + phrasea::getHome('HELP', 'prod'); + echo '
'; +} function proposalsToHTML(&$proposals) { - $html = "
"; - - $nbasesWprop = count($proposals["BASES"]); - - $b = 0; - foreach($proposals["BASES"] as $zbase) - { - if((int)(count($zbase["TERMS"]) > 0)) - { - if(($nbasesWprop > 1)) - { - $style = $b==0 ? "style=\"margin-top:0px;\"":""; - $html .= "". sprintf(_('reponses::propositions pour la base %s'),$zbase["NAME"]).""; - } - $t = 0; - foreach($zbase["TERMS"] as $path=>$props) - { - $style = $t==0 ? "style=\"margin-top:0px;\"":""; - $html .= "

" . sprintf(_('reponses::propositions pour le terme %s'), $props["TERM"]) . "

"; - $html .= $props["HTML"]; - $t++; - } - $b++; - } - } - $html .= "
"; - return($html); + $html = "
"; + + $nbasesWprop = count($proposals["BASES"]); + + $b = 0; + foreach ($proposals["BASES"] as $zbase) + { + if ((int) (count($zbase["TERMS"]) > 0)) + { + if (($nbasesWprop > 1)) + { + $style = $b == 0 ? "style=\"margin-top:0px;\"" : ""; + $html .= "" . sprintf(_('reponses::propositions pour la base %s'), $zbase["NAME"]) . ""; + } + $t = 0; + foreach ($zbase["TERMS"] as $path => $props) + { + $style = $t == 0 ? "style=\"margin-top:0px;\"" : ""; + $html .= "

" . sprintf(_('reponses::propositions pour le terme %s'), $props["TERM"]) . "

"; + $html .= $props["HTML"]; + $t++; + } + $b++; + } + } + $html .= "
"; + return($html); } ?> diff --git a/www/prod/edit.php b/www/prod/edit.php index 318d3bc91b..1b61adff12 100644 --- a/www/prod/edit.php +++ b/www/prod/edit.php @@ -910,7 +910,7 @@ function HTML_Thesaurus(&$html) $class_status = ''; } ?> -
+
diff --git a/www/prod/index.php b/www/prod/index.php index a9ea97b32d..3289b14728 100644 --- a/www/prod/index.php +++ b/www/prod/index.php @@ -769,13 +769,15 @@ $rss_infos = user::getMyRss(); - + + + @@ -783,6 +785,7 @@ $rss_infos = user::getMyRss(); + @@ -1245,6 +1248,17 @@ $rss_infos = user::getMyRss(); ?> +
+
+ +
',$sbase));?> +
+
+
+
+ +
+
-
-
- -
',$sbase));?> -
-
-
-
- -
-
diff --git a/www/prod/jquery.edit.js b/www/prod/jquery.edit.js index 578f2b6734..ff56d1a7a7 100644 --- a/www/prod/jquery.edit.js +++ b/www/prod/jquery.edit.js @@ -852,7 +852,7 @@ function edit_clk_editimg(evt, i) } } - $('#TH_Opreview .PNB10').empty(); + empty_preview_edit(); var selected = $('#EDIT_FILM2 .diapo.selected'); if(selected.length == 1) @@ -1234,6 +1234,7 @@ function edit_applyMultiDesc(evt) var sendorder = ""; var sendChuOrder = ""; + empty_preview_edit(); var t = ""; if(p4.edit.textareaIsDirty && edit_validField(evt, "ask_ok")==false) @@ -1334,7 +1335,7 @@ function edit_applyMultiDesc(evt) function edit_cancelMultiDesc(evt) { - + empty_preview_edit(); var dirty = false; evt.cancelBubble = true; @@ -1502,6 +1503,7 @@ function EditThesaurusSeeker(sbas_id) this.jq = $.ajax({ url: url, data: parms, + type:'POST', success: function(ret) { me.TH_P_node.html("..."); @@ -1855,7 +1857,7 @@ function vsplit2() function setPreviewEdit() { - if(!$('#EDITWINDOW').is(':visible')) + if(!$('#TH_Opreview').is(':visible')) return false; var selected = $('#EDIT_FILM2 .diapo.selected'); @@ -1936,10 +1938,21 @@ function setPreviewEdit() } +function empty_preview_edit() +{ + var el = $('#TH_Opreview .PNB10 object').parent(); + if(el.parent().attr('id') != 'TH_Opreview') + { + el.empty(); + el.remove(); + } + $('#TH_Opreview .PNB10').empty(); +} + function previewEdit(r) { - - $('#TH_Opreview .PNB10').empty().append(p4.edit.T_records[r].preview.preview); + empty_preview_edit(); + $('#TH_Opreview .PNB10').append(p4.edit.T_records[r].preview.preview); var data = p4.edit.T_records[r].preview; @@ -1964,7 +1977,7 @@ function previewEdit(r) } else { - flowplayer("FLASHPREVIEW", '/include/flowplayer/flowplayer-3.2.2.swf',{ + flowplayer("rolloverpreview", '/include/flowplayer/flowplayer-3.2.6.swf',{ clip: { autoPlay: true, autoBuffering:true, @@ -1978,7 +1991,7 @@ function previewEdit(r) }, plugins: { h264streaming: { - url: '/include/flowplayer/flowplayer.pseudostreaming-3.2.2.swf' + url: '/include/flowplayer/flowplayer.pseudostreaming-3.2.6.swf' } } }); @@ -2000,7 +2013,22 @@ function startThisEditing(sbas_id,what,regbasprid,ssel) p4.edit.regbasprid = regbasprid; p4.edit.ssel = ssel; - $('#EDIT_MID_R .tabs').tabs(); + $('#EDIT_MID_R .tabs').tabs( + { + select: function(event, ui) + { + var bloc = $('#EDIT_FILM2 .diapo.video_bloc .previewTips'); + if($(ui.panel).attr('id') == 'TH_Opreview') + { + bloc.hide(); + } + else + { + bloc.show(); + } + } + } + ); $('#divS div.edit_field:odd').addClass('odd'); $('#divS div').bind('mouseover',function(){ diff --git a/www/prod/newtemporary.php b/www/prod/newtemporary.php index 5be42c971b..9ce8ad4572 100644 --- a/www/prod/newtemporary.php +++ b/www/prod/newtemporary.php @@ -30,8 +30,8 @@ if($request->has_post_datas()) $parm = $request->get_parms('name', 'type', 'desc', 'lst', 'coll'); if(trim($parm['name']) != '') - { - if(is_null($parm['type']) || $parm['type']=="CHU") + { + if(is_null($parm['type']) || $parm['type']=="CHU") { try { @@ -61,7 +61,7 @@ if($request->has_post_datas()) try{ $story = new basket(); $story->name = $parm['name']; - $story->desc = $parm['desc']; + $story->desc = strip_tags(str_replace('
',"\n",$parm['desc'])); $story->is_grouping = true; $story->base_id = $parm['coll']; $story->save(); diff --git a/www/prod/share.php b/www/prod/share.php index c37251f019..25ea596309 100644 --- a/www/prod/share.php +++ b/www/prod/share.php @@ -114,7 +114,7 @@ $right = false; switch($type) { case 'video': - $embed = ''. + $embed = ''. ''. ''. ''. diff --git a/www/prod/thesaurus.php b/www/prod/thesaurus.php index 896c27003e..34f1813983 100644 --- a/www/prod/thesaurus.php +++ b/www/prod/thesaurus.php @@ -184,13 +184,14 @@ function T_filter_delayed2(f, delay, mode) var zurl = "/xmlhttp/search_th_term_prod.j.php" + "?sbid=" + sbas[i].sbid + "&t=" + encodeURIComponent(f); - sbas[i].seeker = $.get( - zurl, - [], - function(j, status) - { - if(status == 'success') - { + + sbas[i].seeker = $.ajax({ + url: zurl, + type:'POST', + data: [], + dataType:'json', + success: function(j) + { var z = '#TX_P\\.' + j.parm['sbid'] + '\\.T'; var o = $(z); @@ -200,10 +201,17 @@ function T_filter_delayed2(f, delay, mode) if(isLast) $(z).addClass('last'); - } - }, - "json" - ); + }, + error:function(){ + + }, + timeout:function(){ + + } + }); + + + } } else if(mode=='CANDIDATE') @@ -219,13 +227,13 @@ function T_filter_delayed2(f, delay, mode) zurl += "&t=" + encodeURIComponent(f) + "&field=" + encodeURIComponent(trees.C._selInfos.field); } - sbas[i].seeker = $.get( - zurl, - [], - function(j, status) - { - if(status == 'success') - { + sbas[i].seeker = $.ajax({ + url: zurl, + type:'POST', + data: [], + dataType:'json', + success: function(j) + { var z = '#TX_P\\.' + j.parm['sbid'] + '\\.T'; var o = $(z); @@ -235,10 +243,15 @@ function T_filter_delayed2(f, delay, mode) if(isLast) $(z).addClass('last'); - } - }, - "json" - ); + }, + error:function(){ + + }, + timeout:function(){ + + } + }); + } } }, @@ -358,6 +371,8 @@ function T_acceptCandidates_OK(dlgnode) // $("#THPD_confirm_accept_dlg_msg").dialog("close"); }, + error:function(){}, + timeout:function(){}, _ret: null // private alchemy }; @@ -878,40 +893,12 @@ function replaceEditSel(value) return; } -function crossBrowser_XMLHttpRequest() -{ - var xmlhttp=false; - var e; - try - { - xmlhttp=new XMLHttpRequest(); - } - catch(e) - { - try - { - xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); - } - catch(e) - { - try - { - xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); - } - catch(e) - { - xmlhttp=false; - } - } - } - return xmlhttp; -} function ThesauThesaurusSeeker(sbas_id) { this.sbas_id = sbas_id; this._ctimer = null; - this._xmlhttp = new crossBrowser_XMLHttpRequest(); + this._xmlhttp = null; this.tObj = { 'TH_searching':null , 'TH_P':null , 'TH_K':null }; this.search = function(txt) { if(this._ctimer) @@ -921,69 +908,100 @@ function ThesauThesaurusSeeker(sbas_id) } ; this.search_delayed = function(txt) { var me = this; - this._xmlhttp.abort(); + if($this._xmlttp.abort && typeof $this._xmlttp.abort == 'function') + { + this._xmlhttp.abort(); + } var url = "/xmlhttp/openbranches_prod.x.php"; - var parms = "bid=" + this.sbas_id + "&lng=" + "&t=" + encodeURIComponent(txt); - parms += "&mod=TREE"; - this._xmlhttp.open("POST", url, true); // yes, BEFORE setting callback - this._xmlhttp.onreadystatechange = function() { me.xmlhttpstatechanged(); } ; - this._xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); - this._xmlhttp.send(parms); + var parms = { + bid : this.sbas_id, + lng : "", + t : txt, + mod : "TREE" + }; + + this._xmlhttp = $.ajax({ + url: url, + type:'POST', + data: parms, + success: function(ret) + { + me.xmlhttpstatechanged(ret); + }, + error:function(){ + + }, + timeout:function(){ + + } + }); + this._ctimer = null; } ; this.openBranch = function(id, thid) { var me = this; - this._xmlhttp.abort(); + if($this._xmlttp.abort && typeof $this._xmlttp.abort == 'function') + { + this._xmlhttp.abort(); + } var url = "/xmlhttp/getterm_prod.x.php"; - var parms = "bid=" + sbas_id; - parms += "&lng="; - parms += "&sortsy=1"; - parms += "&id=" + thid; - parms += "&typ=TH"; - this._xmlhttp.open("POST", url, true); // yes, BEFORE setting callback - this._xmlhttp.onreadystatechange = function() { me.xmlhttpstatechanged(id); } ; - this._xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); - this._xmlhttp.send(parms); + var parms = { + bid : this.sbas_id, + lng : "", + sortsy : 1, + id : thid, + typ : "TH" + } + + this._xmlhttp = $.ajax({ + url: url, + type:'POST', + data: parms, + success: function(ret) + { + me.xmlhttpstatechanged(ret, id); + }, + error:function(){ + + }, + timeout:function(){ + + } + }); + }; - this.xmlhttpstatechanged = function(id) { + this.xmlhttpstatechanged = function(ret, id) { try { - if (this._xmlhttp.readyState==4) - { - if(!this.tObj["TH_searching"]) - this.tObj["TH_searching"] = document.getElementById("TH_searching"); - this.tObj["TH_searching"].src = "/skins/icons/ftp-loader-blank.gif"; - - if (this._xmlhttp.status==200) - { - var ret = this._xmlhttp.responseXML; - if(ret) // && (typeof(ret.parsed)=="undefined" || ret.parsed)) - { - var htmlnodes = ret.getElementsByTagName("html"); - if(htmlnodes && htmlnodes.length==1 && (htmlnode=htmlnodes.item(0).firstChild)) - { - if(typeof(id)=="undefined") - { - // called from search or 'auto' : full thesaurus search - if(!this.tObj["TH_P"]) - this.tObj["TH_P"] = document.getElementById("TH_P."+this.sbas_id+".T"); - if(!this.tObj["TH_K"]) - this.tObj["TH_K"] = document.getElementById("TH_K."+this.sbas_id+".T"); - this.tObj["TH_P"].innerHTML = "..."; - this.tObj["TH_K"].className = "h"; - this.tObj["TH_K"].innerHTML = htmlnode.nodeValue; - } - else - { - // called from 'openBranch' - // var js = "document.getElementById('TH_K."+thid+"').innerHTML = \""+htmlnode.nodeValue+"\""; - // self.setTimeout(js, 10); - document.getElementById("TH_K."+id).innerHTML = htmlnode.nodeValue; - } - } - } - } - } + if(!this.tObj["TH_searching"]) + this.tObj["TH_searching"] = document.getElementById("TH_searching"); + this.tObj["TH_searching"].src = "/skins/icons/ftp-loader-blank.gif"; + + if(ret) // && (typeof(ret.parsed)=="undefined" || ret.parsed)) + { + var htmlnodes = ret.getElementsByTagName("html"); + if(htmlnodes && htmlnodes.length==1 && (htmlnode=htmlnodes.item(0).firstChild)) + { + if(typeof(id)=="undefined") + { + // called from search or 'auto' : full thesaurus search + if(!this.tObj["TH_P"]) + this.tObj["TH_P"] = document.getElementById("TH_P."+this.sbas_id+".T"); + if(!this.tObj["TH_K"]) + this.tObj["TH_K"] = document.getElementById("TH_K."+this.sbas_id+".T"); + this.tObj["TH_P"].innerHTML = "..."; + this.tObj["TH_K"].className = "h"; + this.tObj["TH_K"].innerHTML = htmlnode.nodeValue; + } + else + { + // called from 'openBranch' + // var js = "document.getElementById('TH_K."+thid+"').innerHTML = \""+htmlnode.nodeValue+"\""; + // self.setTimeout(js, 10); + document.getElementById("TH_K."+id).innerHTML = htmlnode.nodeValue; + } + } + } } catch(err) {