diff --git a/lib/classes/collection.class.php b/lib/classes/collection.class.php index 53f4ec6df6..03e025fdc5 100644 --- a/lib/classes/collection.class.php +++ b/lib/classes/collection.class.php @@ -200,6 +200,10 @@ class collection implements cache_cacheableInterface $stmt = $this->get_connection()->prepare($sql); $stmt->execute(array(':pub_wm' => $publi, ':coll_id' => $this->get_coll_id())); $stmt->closeCursor(); + + $this->pub_wm = $publi; + + $this->delete_data_from_cache(); } return $this; @@ -219,6 +223,8 @@ class collection implements cache_cacheableInterface $stmt->closeCursor(); $this->name = $name; + + $this->delete_data_from_cache(); return $this; } @@ -396,6 +402,8 @@ class collection implements cache_cacheableInterface $stmt = $this->get_connection()->prepare($sql); $stmt->execute(array(':prefs' => $this->prefs, ':coll_id' => $this->get_coll_id())); $stmt->closeCursor(); + + $this->delete_data_from_cache(); return $this->prefs; } diff --git a/lib/classes/lazaretFile.class.php b/lib/classes/lazaretFile.class.php index 3d4fd25e06..3a4c0646a4 100644 --- a/lib/classes/lazaretFile.class.php +++ b/lib/classes/lazaretFile.class.php @@ -137,7 +137,8 @@ class lazaretFile $pathfile = $registry->get('GV_RootPath') . 'tmp/lazaret/' . $this->filepath; $record = new record_adapter($sbas_id, $record_id); - p4file::substitute($record, $pathfile, $this->filename, false); + $record->substitute_subdef('document', new system_file($pathfile)); + $this->delete(); return $this; diff --git a/lib/classes/p4file.class.php b/lib/classes/p4file.class.php index 10c38e04cb..756372b668 100644 --- a/lib/classes/p4file.class.php +++ b/lib/classes/p4file.class.php @@ -214,311 +214,4 @@ class p4file return $errors; } - public static function substitute(record_Interface $record, $new_pathfile, $filename, $update_filename = false) - { - $appbox = appbox::get_instance(); - $session = $appbox->get_session(); - $registry = $appbox->get_registry(); - - $sbas_id = $record->get_sbas_id(); - $record_id = $record->get_record_id(); - $base_id = $record->get_base_id(); - $connbas = connection::getPDOConnection($sbas_id); - - - $databox = databox::get_instance($sbas_id); - if ($baseprefs = $databox->get_sxml_structure()) - { - $pathhd = p4string::addEndSlash((string) ($baseprefs->path)); - $baseurl = (string) ($baseprefs->baseurl); - } - else - throw new Exception(_('prod::erreur : impossible de lire les preferences de base')); - - if (trim($pathhd) == "" || !is_dir($pathhd)) - throw new Exception(_('prod::substitution::erreur : impossible d\'acceder au dossier de stockage "' . $pathhd . '" ')); - - $sd = $record->get_subdefs('document'); - - if (isset($sd) && isset($sd["document"])) - { - $sd["document"]["path"] = p4string::addEndSlash($sd["document"]["path"]); - - $pathhd = p4string::addEndSlash($sd["document"]["path"]); - $filehd = $sd["document"]["file"]; - - $pathfile = $pathhd . $filehd; - - if (file_exists($pathfile) && !is_dir($pathfile)) - { - if (!@unlink($pathfile)) - throw new Exception(_('prod::substitution::erreur : impossible de supprimer l\'ancien document')); - } - } - else - { - $ext = ""; - $pitmp = pathinfo($filename); - if (isset($pitmp['extension'])) - $ext = $pitmp['extension']; - $filehd = $record_id . "_document." . $ext; - $pathhd = databox::dispatch($pathhd); - - $pathfile = $pathhd . $filehd; - } - - $sql = "DELETE FROM subdef WHERE record_id = :record_id AND name='document'"; - - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':record_id' => $record_id)); - $stmt->closeCursor(); - - $width = $height = 0; - - if (!rename($new_pathfile, $pathfile)) - throw new Exception(_('prod::substitution::document remplace avec succes')); - - if ($tempHD = getimagesize($pathfile)) - { - $width = $tempHD[0]; - $height = $tempHD[1]; - } - - $system_file = new system_file($pathfile); - - - $sql = "INSERT INTO subdef (record_id, name, path, file, baseurl, width, height, mime, size) VALUES - (:record_id, 'document', :pathhd, :file_hd , :baseurl, :width , :height , :mime, :filesize)"; - - $params = array( - ':record_id' => $record_id - , ':pathhd' => $pathhd - , ':file_hd' => $filehd - , ':baseurl' => $baseurl - , ':width' => $width - , ':height' => $height - , ':mime' => $system_file->get_mime() - , ':filesize' => filesize($pathfile) - ); - - $stmt = $connbas->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $session->get_logger($record->get_databox()) - ->log($record, Session_Logger::EVENT_SUBSTITUTE, 'HD', ''); - - $desc = $record->get_xml(); - - $doc = new DOMDocument(); - $doc->loadXML($desc); - $params = $doc->getElementsByTagName('doc'); - $newname = null; - - foreach ($params as $param) - { - $oldname = $param->getAttribute('originalname'); - if ($oldname) - { - $oldpi = pathinfo($oldname); - $val = ""; - $pi = pathinfo($filename); - if (isset($pi["extension"])) - $val = $pi["extension"]; - - if ($update_filename) - $newname = $pi['basename']; - else - $newname = $oldpi['filename'] . "." . $val; - } - if ($newname) - $param->setAttribute('originalname', $newname); - $param->removeAttribute('channels'); - $param->removeAttribute('bits'); - - $param->setAttribute('height', $height); - $param->setAttribute('width', $width); - $param->setAttribute('size', filesize($pathfile)); - $param->setAttribute('mime', $system_file->get_mime()); - if (isset($tempHD["bits"])) - $param->setAttribute('bits', $tempHD["bits"]); - if (isset($tempHD["channels"])) - $param->setAttribute('channels', $tempHD["channels"]); - } - - $xp_rec = new DOMXPath($doc); - $databox = databox::get_instance($sbas_id); - $sx_struct = $databox->get_sxml_structure(); - foreach ($sx_struct->description->children() as $fn => $fv) - { - if (isset($fv["src"]) && (substr($fv["src"], 0, 2) == "tf")) - { - switch ($fv["src"]) - { - case "tf-chgdocdate": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = date('Y/m/d H:i:s', time()); - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = date('Y/m/d H:i:s', time()); - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-filename": - if ($newname && ($recdesc = $xp_rec->query("/record/description/$fn"))) - { - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $newname; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $newname; - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-extension": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - $val = ""; - $pi = pathinfo($filename); - if (isset($pi["extension"])) - $val = $pi["extension"]; - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $val; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $val; - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-mimetype": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - $val = $system_file->get_mime(); - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $val; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $val; - $newnode = $recdesc->appendChild($node); - } - } - - break; - - case "tf-size": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = filesize($pathfile); - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = filesize($pathfile); - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-width": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $width; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $width; - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-height": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $height; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $height; - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-bits": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - $val = ""; - if (isset($tempHD["bits"])) - $val = $tempHD["bits"]; - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $val; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $val; - $newnode = $recdesc->appendChild($node); - } - } - break; - - case "tf-channels": - if ($recdesc = $xp_rec->query("/record/description/$fn")) - { - $val = ""; - if (isset($tempHD["channels"])) - $val = $tempHD["channels"]; - if ($recdesc->item(0)) - $recdesc->item(0)->nodeValue = $val; - else - { - $recdesc = $xp_rec->query("/record/description")->item(0); - $node = $doc->createElement($fn); - $node->nodeValue = $val; - $newnode = $recdesc->appendChild($node); - } - } - break; - } - } - } - $newXml = $doc->savexml(); - - $record->set_xml($newXml); - - $sql = "UPDATE record SET status=status & ~3, moddate=NOW() - WHERE record_id = :record_id"; - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':record_id' => $record_id)); - $stmt->closeCursor(); - - $record->write_metas(); - $filesToSet = null; - $filesToSet[] = $pathfile; - - return true; - } - } diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index 5eb39c557c..50f590a46e 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -825,6 +825,43 @@ class record_adapter implements record_Interface, cache_cacheableInterface return $this->original_name; } + public function set_original_name($original_name) + { + $this->original_name = $original_name; + + foreach ($this->get_caption()->get_fields() as $field) + { + if ($field->get_databox_field()->get_source() != metadata_description_PHRASEANET_tffilename::get_source()) + { + continue; + } + + $this->set_metadatas( + array( + 'meta_struct_id' => $field->get_meta_struct_id() + , 'meta_id' => get_meta_id + , 'value' => array($original_name) + ) + ); + } + + $sql = 'UPDATE record + SET originalname = :originalname WHERE record_id = :record_id'; + + $params = array( + ':originalname' => $original_name + , ':record_id' => $this->get_record_id() + ); + + $stmt = $this->get_databox()->get_connection()->prepare($sql); + $stmt->execute($params); + $stmt->closeCursor(); + + $this->delete_data_from_cache(); + + return $this; + } + /** * * @return string @@ -1028,53 +1065,82 @@ class record_adapter implements record_Interface, cache_cacheableInterface . '.' . $pathfile->get_extension(); $base_url = ''; + $original_file = $subdef_def = false; - $subdefs = $this->get_databox()->get_subdef_structure(); - - foreach ($subdefs as $type => $datas) + if ($name == 'document') { - if ($this->get_type() != $type) - continue; + $baseprefs = $this->get_databox()->get_sxml_structure(); - if (!isset($datas[$name])) - throw new Exception('No available subdef declaration for this type and name'); + $pathhd = p4string::addEndSlash((string) ($baseprefs->path)); - $subdef_def = $datas[$name]; - break; + $filehd = $this->get_record_id() . "_document." . $pathfile->get_extension(true); + $pathhd = databox::dispatch($pathhd); + + copy($pathfile->getPathname(), $pathhd . $filehd); + + $system_file = new system_file($pathhd . $filehd); + + $meta_writable = true; } - - if (!$subdef_def) - throw new Exception('Unknown subdef name'); - - try + else { - $value = $this->get_subdef($name); - - if ($value->is_substituted()) + $subdefs = $this->get_databox()->get_subdef_structure(); + + foreach ($subdefs as $type => $datas) { - throw new Exception('Cannot replace a substitution'); + if ($this->get_type() != $type) + continue; + + if (!isset($datas[$name])) + throw new Exception('No available subdef declaration for this type and name'); + + $subdef_def = $datas[$name]; + break; } - - $original_file = p4string::addEndSlash($value->get_path()) . $value->get_file(); - unlink($original_file); - } - catch (Exception $e) - { - $path = databox::dispatch($subdef_def->get_path()); - system_file::mkdir($path); - $original_file = $path . $newfilename; - } - $path_file_dest = $original_file; + if (!$subdef_def) + throw new Exception('Unknown subdef name'); - if (trim($subdef_def->get_baseurl()) !== '') - { - $base_url = str_replace( - array((string) $subdef_def->get_path(), $newfilename) - , array((string) $subdef_def->get_baseurl(), '') - , $path_file_dest - ); + try + { + $value = $this->get_subdef($name); + + if ($value->is_substituted()) + { + throw new Exception('Cannot replace a substitution'); + } + + $original_file = p4string::addEndSlash($value->get_path()) . $value->get_file(); + unlink($original_file); + } + catch (Exception $e) + { + $path = databox::dispatch($subdef_def->get_path()); + system_file::mkdir($path); + $original_file = $path . $newfilename; + } + + $path_file_dest = $original_file; + + if (trim($subdef_def->get_baseurl()) !== '') + { + $base_url = str_replace( + array((string) $subdef_def->get_path(), $newfilename) + , array((string) $subdef_def->get_baseurl(), '') + , $path_file_dest + ); + } + + $registry = registry::get_instance(); + + $adapter = new binaryAdapter_image_resize($registry); + $adapter->execute($pathfile, $path_file_dest, $subdef_def->get_options()); + + $system_file = new system_file($path_file_dest); + $system_file->chmod(); + + $meta_writable = $subdef_def->meta_writeable(); } try @@ -1090,14 +1156,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface ) ); - $registry = registry::get_instance(); - - $adapter = new binaryAdapter_image_resize($registry); - $adapter->execute($pathfile, $path_file_dest, $subdef_def->get_options()); - - $system_file = new system_file($path_file_dest); - $system_file->chmod(); - $image_size = $system_file->get_technical_datas(); $sql = 'INSERT INTO subdef @@ -1107,6 +1165,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface (:record_id, :name, :baseurl, :filename, :width, :height, :mime, :path, :filesize, "1")'; + echo "substitute subdef $name with $base_url ".$system_file->getPath()." ".$system_file->getFilename()."
"; $stmt = $connbas->prepare($sql); $stmt->execute(array( @@ -1129,7 +1188,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $this->delete_data_from_cache(self::CACHE_SUBDEFS); - if ($subdef_def->meta_writeable()) + if ($meta_writable) { $this->write_metas(); } @@ -1137,12 +1196,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $this->rebuild_subdefs(); } + + $type = $name == 'document' ? 'HD' : $name; + + $session->get_logger($record->get_databox()) + ->log($record, Session_Logger::EVENT_SUBSTITUTE, $type, ''); } catch (Exception $e) { unset($e); } + return $this; } @@ -1163,6 +1228,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface ) ); + $this->reindex(); + return $this; } @@ -1386,7 +1453,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface * @param boolean $is_grouping * @return record_adapter */ - public static function create(collection $collection, system_file &$system_file, $original_name=false, $is_grouping = false) + public static function create(collection $collection, system_file &$system_file, $original_name = false, $is_grouping = false) { $type = $system_file->get_phrasea_type(); @@ -1893,7 +1960,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface * @param int $how_many * @return type */ - public static function get_records_by_originalname(databox $databox, $original_name, $offset_start=0, $how_many=10) + public static function get_records_by_originalname(databox $databox, $original_name, $offset_start = 0, $how_many = 10) { $offset_start = (int) ($offset_start < 0 ? 0 : $offset_start); $how_many = (int) (($how_many > 20 || $how_many < 1) ? 10 : $how_many); diff --git a/lib/classes/record/preview.class.php b/lib/classes/record/preview.class.php index a5179b4449..9aeb8cd758 100644 --- a/lib/classes/record/preview.class.php +++ b/lib/classes/record/preview.class.php @@ -381,11 +381,22 @@ class record_preview extends record_adapter if (!isset($tab[$hour][$site][$action][$row['usr_id']])) { + $user = null; + + try + { + $user = \User_Adapter::getInstance($row['usr_id'], $appbox); + } + catch (Exception $e) + { + + } + $tab[$hour][$site][$action][$row['usr_id']] = array( 'final' => array() , 'comment' => array() - , 'user' => \User_Adapter::getInstance($row['usr_id'], $appbox) + , 'user' => $user ); } diff --git a/lib/classes/set/export.class.php b/lib/classes/set/export.class.php index 30fb5efe61..a04644d7fb 100644 --- a/lib/classes/set/export.class.php +++ b/lib/classes/set/export.class.php @@ -99,7 +99,7 @@ class set_export extends set_abstract { $record = new record_adapter($basrec[0], $basrec[1]); } - catch(Exception_Record_AdapterNotFound $e) + catch (Exception_Record_AdapterNotFound $e) { continue; } @@ -411,7 +411,7 @@ class set_export extends set_abstract * @param boolean $rename_title * @return Array */ - public function prepare_export(Array $subdefs, $rename_title=false) + public function prepare_export(Array $subdefs, $rename_title = false) { if (!is_array($subdefs)) { @@ -434,6 +434,7 @@ class set_export extends set_abstract foreach ($this->elements as $download_element) { + echo "eleme"; $id = count($files); $files[$id] = array( @@ -481,7 +482,7 @@ class set_export extends set_abstract $sd = $download_element->get_subdefs(); foreach ($download_element->get_downloadable() as $name => $properties) - { + { if ($properties === false || !in_array($name, $subdefs)) { continue; @@ -490,10 +491,6 @@ class set_export extends set_abstract { continue; } - if (!isset($sd[$name])) - { - continue; - } set_time_limit(100); $subdef_export = $subdef_alive = false; @@ -689,7 +686,9 @@ class set_export extends set_abstract system_file::mkdir($caption_dir); $desc = self::get_caption( - $download_element->get_base_id(), $download_element->get_record_id(), $session->get_ses_id() + $download_element->get_base_id() + , $download_element->get_record_id() + , $session->get_ses_id() ); $file = $files[$id]["export_name"] @@ -717,7 +716,11 @@ class set_export extends set_abstract $desc = self::get_caption( - $download_element->get_base_id(), $download_element->get_record_id(), $session->get_ses_id(), true, 'yaml' + $download_element->get_base_id() + , $download_element->get_record_id() + , $session->get_ses_id() + , true + , 'yaml' ); $file = $files[$id]["export_name"] @@ -736,6 +739,7 @@ class set_export extends set_abstract } } } + $this->list = array( 'files' => $files, 'names' => $file_names, @@ -743,6 +747,7 @@ class set_export extends set_abstract 'count' => $n_files ); + return $this->list; } @@ -762,7 +767,6 @@ class set_export extends set_abstract return false; } if (isset($list['complete']) && $list['complete'] === true) - return; @@ -839,7 +843,7 @@ class set_export extends set_abstract * @param boolean $check_rights * @return string */ - public static function get_caption($bas, $rec, $check_rights=true, $format = 'xml') + public static function get_caption($bas, $rec, $check_rights = true, $format = 'xml') { $dom = new DOMDocument(); $dom->formatOutput = true; @@ -954,7 +958,7 @@ class set_export extends set_abstract * @return Void */ public static function stream_file( - $file, $exportname, $mime, $disposition='attachment') + $file, $exportname, $mime, $disposition = 'attachment') { require_once __DIR__ . "/../../../lib/vendor/Silex/autoload.php"; $registry = registry::get_instance(); @@ -1003,11 +1007,11 @@ class set_export extends set_abstract * @todo : merge this shitty fix with Response object. * */ - if(!headers_sent()) + if (!headers_sent()) { header("Pragma: public"); } - + $response->headers->set('Content-Type', $mime); $response->headers->set('Content-Name', $exportname); $response->headers->set('Content-Disposition', $disposition . "; filename=" . $exportname . ";"); @@ -1028,7 +1032,7 @@ class set_export extends set_abstract * @param String $disposition * @return Void */ - public static function stream_data($data, $exportname, $mime, $disposition='attachment') + public static function stream_data($data, $exportname, $mime, $disposition = 'attachment') { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); @@ -1063,7 +1067,7 @@ class set_export extends set_abstract $user = false; if ($anonymous) { - + } else { diff --git a/www/prod/chghddocument.php b/www/prod/chghddocument.php index 4748020fe3..274e3c45b3 100644 --- a/www/prod/chghddocument.php +++ b/www/prod/chghddocument.php @@ -48,8 +48,11 @@ if (!isset($_FILES["newHD"]) || $_FILES["newHD"]["tmp_name"] == "" || $_FILES["n try { $record = new record_adapter($parm['sbas_id'], $parm['record_id']); - p4file::substitute($record, $_FILES["newHD"]["tmp_name"], $_FILES["newHD"]["name"], ($parm['ccfilename'] == '1')); -} + $record->substitute_subdef('document', new system_file($_FILES["newHD"]["tmp_name"])); + if($parm['ccfilename'] == '1') + { + $record->set_original_name($_FILES["newHD"]["name"]); + } catch (Exception $e) { echo '
', $e->getMessage(), '

'; diff --git a/www/prod/jquery.edit.js b/www/prod/jquery.edit.js index f2e65679dd..82666f51ad 100644 --- a/www/prod/jquery.edit.js +++ b/www/prod/jquery.edit.js @@ -1836,27 +1836,27 @@ function preset_load(preset_id) { if(p4.edit.T_fields[i].preset != null) { + if(!(""+i in p4.edit.T_records[r].fields)) + { + p4.edit.T_records[r].fields[""+i] = {}; + } + if(p4.edit.T_fields[i].multi) { - p4.edit.T_records[r].fields[""+i] = { - value:[], - "meta_struct_id":p4.edit.T_fields[i].meta_struct_id, - dirty:true - };// = { - var n = 0; + p4.edit.T_records[r].fields[""+i].value = []; + p4.edit.T_records[r].fields[""+i].meta_struct_id = p4.edit.T_fields[i].meta_struct_id; + p4.edit.T_records[r].fields[""+i].dirty = true; + for(val in p4.edit.T_fields[i].preset) { - p4.edit.T_records[r].fields[""+i].value[n] = p4.edit.T_fields[i].preset[val]; - n++; + p4.edit.T_records[r].fields[""+i].push(p4.edit.T_fields[i].preset[val]); } } else { - p4.edit.T_records[r].fields[""+i] = { - "value":p4.edit.T_fields[i].preset[0], - "meta_struct_id":p4.edit.T_fields[i].meta_struct_id, - "dirty":true - }; + p4.edit.T_records[r].fields[""+i].value = p4.edit.T_fields[i].preset[0]; + p4.edit.T_records[r].fields[""+i].meta_struct_id = p4.edit.T_fields[i].meta_struct_id; + p4.edit.T_records[r].fields[""+i].dirty = true; } } }