function begin_document($path) { global $PHP_SELF, $base_url, $id_pool, $assessments, $basepath, $collection; $id = get_full_path($basepath, $path); print_assessments($id); print "<a id='{$id}' href=\"{$base_url}/article?collection={$collection}&id_pool={$id_pool}&file={$id}\">"; }
function add_pdf_to_db($path, $attributes) { global $db; $path = canonicalize_path($path); if (!file_exists(get_full_path($path))) { err_bad_input_data('file_path', $path, "file doesn't exist"); } $attributes['md5'] = get_md5_hash($path); if (!$attributes['md5']) { err_internal("could not generate hash of file {$path}"); } // TODO: find number of pages $pages = 0; $sql = "INSERT INTO files VALUES (NULL, '" . addslashes($path) . "'" . ', ' . ($attributes['title'] ? "'" . addslashes($attributes['title']) . "'" : 'NULL') . ', ' . ($attributes['md5'] ? "'" . addslashes($attributes['md5']) . "'" : 'NULL') . ', ' . ($attributes['date'] ? "'" . addslashes($attributes['date']) . "'" : 'NULL') . ", " . $pages . ', ' . ($attributes['origin'] ? "'" . addslashes($attributes['origin']) . "'" : 'NULL') . ', ' . ($attributes['recipient'] ? "'" . addslashes($attributes['recipient']) . "'" : 'NULL') . ")"; $db->exec($sql); return $db->lastInsertRowID(); }
// it has no db record... insert it echo "inserting: {$path} \n"; $attributes = array('md5' => $md5); print_r($attributes); add_pdf_to_db($path, $attributes); } } } $orphans = array(); // check every existing db record foreach (find_pdfs_all() as $pdf_id) { $pdf = get_pdf_info($pdf_id); if ($pdf) { $path = $pdf['path']; $cpath = canonicalize_path($path); if (!file_exists(get_full_path($path))) { // the file was deleted. keep the data, but make it an orphan (no path) echo "*** file {$cpath} doesn't exist! adding to orphans list\n"; $orphans[] = $pdf_id; } else { if ($path != $cpath) { // the path is not a cannonical path... fix it echo "path not canoncial: {$path} -> {$cpath}\n"; $other_pdf_id = get_pdf_id($cpath); if ($other_pdf_id) { // another record is using this file with an alternative path name... merge the records only // TODO: merge metadata only -- they're using the same file echo "redundant path with {$other_pdf_id}: merge with {$pdf_id} \n"; merge_pdf_metadata(array($pdf_id, $other_pdf_id), $cpath); } else { echo "update path to be canonical...\n";
function begin_document($path) { global $PHP_SELF, $base_url, $id_pool, $assessments, $basepath, $collection, $document, $phpext; // print "$basepath"; $id = get_full_path($basepath, $path); if ($document[$id]) { $a =& $document[$id]; if ($a[1]) { print "<span style=\"padding: 2px; border: 1px dashed blue\" title=\"in pool\">"; } else { print "<span>"; } switch ($a[0]) { case "0": print "<img style=\"vertical-align: center;\" src=\"{$base_url}/img/mode_highlight\" title=\"highlighting mode\" alt=\"[highlighting]\"/>"; break; case "1": print "<img style=\"vertical-align: center;\" src=\"{$base_url}/img/nok\" title=\"assessing mode (not validated)\" alt=\"[assessing]\"/>"; break; case "2": print "<img style=\"vertical-align: center;\" src=\"{$base_url}/img/ok\" title=\"assessing mode (validated)\" alt=\"[validated]\"/>"; break; } print "</span> "; } print "<a id='" . xmlspecialchars($id) . "'" . ($a[1] ? " name='toAssess'" : "") . " href=\"{$base_url}/article{$phpext}?collection={$collection}&id_pool={$id_pool}&file={$id}\">"; }
/** * Recursive function to get the full categories path of a specified categorie. * * @param table of all the categories, 2 dimension tables, first dimension for cat codes, second for names, * parent's cat code. * @param $catcode string the categorie we want to have its full path from root categorie * @param $separator string * @return void */ function get_full_path($categories, $catcode = NULL, $separator = ' > ') { //Find parent code $parent = null; foreach ($categories as $currentCat) { if ($currentCat['code'] == $catcode) { $parent = $currentCat['parent']; $childTreePos = $currentCat['treePos']; // for protection anti loop } } // RECURSION : find parent categorie in table if ($parent == null) { return $catcode; } foreach ($categories as $currentCat) { if ($currentCat['code'] == $parent) { if ($currentCat['treePos'] >= $childTreePos) { return claro_failure::set_failure('loop_in_structure'); } if ($parent == $catcode) { return claro_failure::set_failure('loop_in_structure'); } return get_full_path($categories, $parent, $separator) . $separator . $catcode; } } }