PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/dmscripts/DMSystem.php

https://github.com/archives-of-michigan/seekingmichigan.org-ContentDM
PHP | 2696 lines | 2692 code | 4 blank | 0 comment | 2 complexity | e4937c635df74f466aefe98ced5ae8c2 MD5 | raw file
  1. <?php
  2. $compound_objects = array(
  3. '/uw/9876' => <<<XML
  4. <cpd>
  5. <page>
  6. <pageptr>1609</pageptr>
  7. </page>
  8. <page>
  9. <pageptr>1610</pageptr>
  10. </page>
  11. </cpd>
  12. XML
  13. );
  14. $items = array(
  15. '/uw/1609' => <<<XML
  16. <xml>
  17. <title>Adrian (Mich.)</title>
  18. <subjec>Adrian High School (Adrian, Mich.); schools</subjec>
  19. <descri>High School Building in Adrian (Mich.); c. 1920.</descri>
  20. <creato></creato>
  21. <date>c. 1920</date>
  22. <format>Image</format>
  23. <type>Postcard - Color</type>
  24. <identi>PH.10458; Town and City Scenes-Adrian-PF.2104</identi>
  25. <negati>21568</negati>
  26. <source>Part of the Souvenir Folder of Adrian (Mich.)</source>
  27. <rights>Use of this image requires the permission of the Archives of Michigan</rights>
  28. <order>To order please email archives@mi.gov</order>
  29. <featur></featur>
  30. <locati></locati>
  31. <oclc></oclc>
  32. <answer></answer>
  33. <ead></ead>
  34. <fullrs></fullrs>
  35. <find>1609.jp2</find>
  36. <dmaccess></dmaccess>
  37. <dmimage></dmimage>
  38. <dmcreated>2009-08-28</dmcreated>
  39. <dmmodified>2009-08-28</dmmodified>
  40. <dmoclcno></dmoclcno>
  41. <dmrecord>1607</dmrecord>
  42. </xml>
  43. XML,
  44. '/uw/1610' => <<<XML
  45. <xml>
  46. <title>Adrian (Mich.)</title>
  47. <subjec>Adrian High School (Adrian, Mich.); schools</subjec>
  48. <descri>High School Building in Adrian (Mich.); c. 1920.</descri>
  49. <creato></creato>
  50. <date>c. 1920</date>
  51. <format>Image</format>
  52. <type>Postcard - Color</type>
  53. <identi>PH.10458; Town and City Scenes-Adrian-PF.2104</identi>
  54. <negati>21568</negati>
  55. <source>Part of the Souvenir Folder of Adrian (Mich.)</source>
  56. <rights>Use of this image requires the permission of the Archives of Michigan</rights>
  57. <order>To order please email archives@mi.gov</order>
  58. <featur></featur>
  59. <locati></locati>
  60. <oclc></oclc>
  61. <answer></answer>
  62. <ead></ead>
  63. <fullrs></fullrs>
  64. <find>1610.jp2</find>
  65. <dmaccess></dmaccess>
  66. <dmimage></dmimage>
  67. <dmcreated>2009-08-28</dmcreated>
  68. <dmmodified>2009-08-28</dmmodified>
  69. <dmoclcno></dmoclcno>
  70. <dmrecord>1607</dmrecord>
  71. </xml>
  72. XML
  73. );
  74. $slash = getPath();
  75. include($slash."dmscripts/DMUser.php");
  76. define("CATALOG_FILE",$slash."catalog.txt");
  77. define("DC_FILE",$slash."dc.txt");
  78. define("IMAGE_FILE",$slash."../conf/imageconf.txt");
  79. define("PUB_FILE",$slash."../conf/dbpriv.txt");
  80. define("CONF_DIR",$slash."../conf");
  81. define("FIND_DIR",$slash."../find");
  82. define("FINDCONF_FILE",$slash."../conf/findconf.txt");
  83. define("MAX_FAVORITES",100);
  84. define("WORDSIZE",32);
  85. function getPath() {
  86. $slash = '';
  87. if ( array_key_exists( "HTTP_HOST", $_SERVER ) ) {
  88. $num = substr_count($_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"],'/');
  89. }
  90. else {
  91. $path = str_replace ( '\\', '/', getcwd() );
  92. unset ($m);
  93. if ( preg_match( "#.*(/docs/.*)$#is", $path, $m ) ) {
  94. $num = substr_count($m[1],'/');
  95. }
  96. else {
  97. die ("Error" . " File: " . __FILE__ . " on line: " . __LINE__);
  98. }
  99. }
  100. for($i=1;$i<$num;$i++) {
  101. $slash .= '../';
  102. }
  103. return $slash;
  104. }
  105. /* Read list of collections available on the Server */
  106. function &dmGetCollectionList() {
  107. if ((file_exists(PUB_FILE)) && (filesize(PUB_FILE) > 0)) {
  108. $handle = fopen(PUB_FILE,"r");
  109. $dbprivlist = fread($handle,filesize(PUB_FILE));
  110. fclose($handle);
  111. }
  112. else
  113. $dbprivlist = "";
  114. /* Open the catalog.txt file */
  115. $catalogFile = fopen(CATALOG_FILE,"r");
  116. if (!($catalogFile)) {
  117. print("Error opening catalog file");
  118. exit;
  119. }
  120. $cat = array();
  121. $n = 0;
  122. /* Read the collections from the catalog line by line */
  123. while (!feof($catalogFile)) {
  124. $s = fgets($catalogFile,512);
  125. if (substr($s,0,1) == "/") {
  126. $s = str_replace("\r","",$s);
  127. $s = str_replace("\n","",$s);
  128. $alias = strtok($s,"\t");
  129. $name = strtok("\t");
  130. $path = strtok("\t");
  131. $allow = 0;
  132. $privfile = $path . "/index/etc/priv.txt";
  133. $fd = fopen($privfile,"r");
  134. if ($fd) {
  135. $t = trim(fgets($fd,2048)," \r\n");
  136. if ($t != "") {
  137. $rc = CheckUser($t);
  138. if ($rc > 0) {
  139. $allow = 1;
  140. }
  141. }
  142. else {
  143. $allow = 1;
  144. }
  145. }
  146. else {
  147. $allow = 1;
  148. }
  149. if ($allow == 1) {
  150. $temp = $alias . "\n";
  151. if ((isset($_COOKIE['DMID'])) || (!strstr($dbprivlist,$temp))) {
  152. $cat[$n]["alias"] = $alias;
  153. $cat[$n]["name"] = $name;
  154. $cat[$n]["path"] = $path;
  155. $n++;
  156. }
  157. }
  158. }
  159. }
  160. fclose($catalogFile);
  161. return($cat);
  162. }
  163. /* Check the user against the permission string */
  164. /* Returns: 0 = no access, 1 = full access, 2 = metadata only */
  165. function CheckUser($t) {
  166. $user = dmGetUser();
  167. if (isset($_SERVER["REMOTE_ADDR"]))
  168. $ip = $_SERVER["REMOTE_ADDR"];
  169. else
  170. $ip = "";
  171. $rc = 0;
  172. $deny = 0;
  173. $p = trim(strtok($t,";"));
  174. while ($p != "") {
  175. if ($p == "deny:file") {
  176. $deny = 1;
  177. }
  178. elseif (substr($p,0,3) == "ip:") { /* ip address restriction */
  179. $ipstring = substr($p,3,strlen($p)-3);
  180. if (CheckIPString($ipstring,$ip)) {
  181. // $ipstem = explode("*",$ipstring);
  182. // if ((trim($ipstem[0]) != "") && (strncmp($ip,trim($ipstem[0]),strlen(trim($ipstem[0]))) == 0)) {
  183. $rc = 1;
  184. break;
  185. }
  186. }
  187. else { /* user restriction */
  188. $luser = strtolower($user);
  189. $lp = strtolower($p);
  190. if (strcmp($luser,$lp) == 0) {
  191. $rc = 1;
  192. break;
  193. }
  194. }
  195. $p = trim(strtok(";"));
  196. }
  197. if (($rc == 0) && ($deny == 1)) {
  198. $rc = 2;
  199. }
  200. return($rc);
  201. }
  202. /* Check the IP string */
  203. function CheckIPString($s,$ip) {
  204. $rc = 0;
  205. if (!strstr($s,"*") && !strstr($s,"-")) {
  206. if (trim($s) == trim($ip))
  207. $rc = 1;
  208. }
  209. else {
  210. $sbuf = explode(".",$s,4);
  211. $ipbuf = explode(".",$ip,4);
  212. $j = count($sbuf);
  213. if ($j < 4) {
  214. for ($i = $j; $i < 4; $i++)
  215. $sbuf[$i] = "";
  216. }
  217. $j = count($ipbuf);
  218. if ($j < 4) {
  219. for ($i = $j; $i < 4; $i++)
  220. $ipbuf[$i] = "";
  221. }
  222. $j = 0;
  223. for ($i = 0; $i < 4; $i++) {
  224. if (($sbuf[$i] == "*") || ($sbuf[$i] == ""))
  225. $j++;
  226. elseif (strstr($sbuf[$i],"-")) {
  227. $range = explode("-",$sbuf[$i],2);
  228. if (count($range) < 2)
  229. break;
  230. if (($ipbuf[$i] >= $range[0]) && ($ipbuf[$i] <= $range[1]))
  231. $j++;
  232. }
  233. else {
  234. if ($sbuf[$i] == $ipbuf[$i])
  235. $j++;
  236. else
  237. break;
  238. }
  239. }
  240. if ($j == 4)
  241. $rc = 1;
  242. }
  243. return($rc);
  244. }
  245. /* Read the collection parameters for a given collection */
  246. /* Returns: -2 = error, -1 = no permission, 1 = full access, 2 = metadata only */
  247. function dmGetCollectionParameters($alias,&$name,&$path) {
  248. /* Open the catalog.txt file */
  249. $catalogFile = fopen(CATALOG_FILE,"r");
  250. if (!($catalogFile)) {
  251. print("Error opening catalog file<br>\n");
  252. exit;
  253. }
  254. $rc = -2;
  255. /* Read the collections from the catalog line by line */
  256. while (!feof($catalogFile)) {
  257. $s = fgets($catalogFile,512);
  258. if (substr($s,0,1) == "/") {
  259. $s = str_replace("\r","",$s);
  260. $s = str_replace("\n","",$s);
  261. $temp = strtok($s,"\t");
  262. if ($temp == $alias) {
  263. $name = strtok("\t");
  264. $path = strtok("\t");
  265. $rc = 0;
  266. break;
  267. }
  268. }
  269. }
  270. fclose($catalogFile);
  271. if ($rc == 0) {
  272. $allow = 0;
  273. $privfile = $path . "/index/etc/priv.txt";
  274. if (file_exists($privfile)) {
  275. $fd = fopen($privfile,"r");
  276. if ($fd) {
  277. $t = trim(fgets($fd,2048)," \r\n");
  278. fclose($fd);
  279. if ($t != "") {
  280. $rc = CheckUser($t);
  281. if ($rc > 0) {
  282. $allow = 1;
  283. }
  284. }
  285. else {
  286. $allow = 1;
  287. }
  288. }
  289. else {
  290. $allow = 1;
  291. }
  292. if ($allow == 0) {
  293. $rc = -1;
  294. }
  295. }
  296. else {
  297. $rc = -2;
  298. }
  299. }
  300. return($rc);
  301. }
  302. /* Read the collection field properties */
  303. function &dmGetCollectionFieldInfo($alias) {
  304. $rc = dmGetCollectionParameters($alias,$name,$path);
  305. if ($rc < 0) {
  306. print("Error looking up collection $alias<br>\n");
  307. if ($rc == -1) {
  308. print("No permission to access this collection<br>\n");
  309. }
  310. exit;
  311. }
  312. $conf = array();
  313. $n = 0;
  314. $fn = $path . "/index/etc/config.txt";
  315. $configFile = fopen($fn,"r");
  316. if (!($configFile)) {
  317. print("Error opening configuration file $fn<br>\n");
  318. exit;
  319. }
  320. while (!feof($configFile)) {
  321. $s = fgets($configFile,512);
  322. $s = str_replace("\r","",$s);
  323. $s = str_replace("\n","",$s);
  324. if (strlen($s) > 0) {
  325. $t = substr($s,0,1);
  326. if (($t != "*") && ($t != ">") && ($t != " ")) {
  327. $conf[$n]["name"] = strtok($s,":");
  328. $conf[$n]["nick"] = strtok(":");
  329. $conf[$n]["type"] = strtok(":");
  330. $temp = strtok(":");
  331. if ($temp == "BIG") {
  332. $conf[$n]["size"] = 1;
  333. }
  334. else {
  335. $conf[$n]["size"] = 0;
  336. }
  337. $temp = strtok(":");
  338. $conf[$n]["find"] = $temp;
  339. $temp = strtok(":");
  340. if (($temp == "REQ") || ($conf[$n]["nick"] == "title")) {
  341. $conf[$n]["req"] = 1;
  342. }
  343. else {
  344. $conf[$n]["req"] = 0;
  345. }
  346. $temp = strtok(":");
  347. if ($temp == "SEARCH") {
  348. $conf[$n]["search"] = 1;
  349. }
  350. else {
  351. $conf[$n]["search"] = 0;
  352. }
  353. $temp = strtok(":");
  354. if ($temp == "HIDE") {
  355. $conf[$n]["hide"] = 1;
  356. }
  357. else {
  358. $conf[$n]["hide"] = 0;
  359. }
  360. $conf[$n]["vocdb"] = "";
  361. $temp = strtok(":");
  362. if (substr($temp,0,5) == "VOCAB") {
  363. $conf[$n]["vocab"] = 1;
  364. if ((strlen($temp) > 5) && (substr($temp,5,1) == "-")) {
  365. $tsdb = trim(substr($temp,6));
  366. $conf[$n]["vocdb"] = $tsdb;
  367. }
  368. }
  369. else {
  370. $conf[$n]["vocab"] = 0;
  371. }
  372. $conf[$n]["dc"] = strtok(":");
  373. $conf[$n]["admin"] = 0;
  374. $conf[$n]["readonly"] = 0;
  375. $n++;
  376. }
  377. }
  378. }
  379. fclose($configFile);
  380. $fn = $path . "/index/etc/configadmin.txt";
  381. if (file_exists($fn)) {
  382. $configFile = fopen($fn,"r");
  383. if (!($configFile)) {
  384. print("Error opening configuration file $fn<br>\n");
  385. exit;
  386. }
  387. while (!feof($configFile)) {
  388. $s = fgets($configFile,512);
  389. $s = str_replace("\r","",$s);
  390. $s = str_replace("\n","",$s);
  391. if (strlen($s) > 0) {
  392. $t = substr($s,0,1);
  393. if (($t != "*") && ($t != ">") && ($t != " ")) {
  394. $conf[$n]["name"] = strtok($s,":");
  395. $conf[$n]["nick"] = strtok(":");
  396. $conf[$n]["type"] = strtok(":");
  397. if ($conf[$n]["nick"] == "fullrs")
  398. $conf[$n]["type"] = "FULLRES";
  399. $temp = strtok(":");
  400. if ($temp == "BIG") {
  401. $conf[$n]["size"] = 1;
  402. }
  403. else {
  404. $conf[$n]["size"] = 0;
  405. }
  406. $temp = strtok(":");
  407. $conf[$n]["find"] = $temp;
  408. $temp = strtok(":");
  409. $conf[$n]["req"] = 1;
  410. $temp = strtok(":");
  411. if ($temp == "SEARCH") {
  412. $conf[$n]["search"] = 1;
  413. }
  414. else {
  415. $conf[$n]["search"] = 0;
  416. }
  417. $temp = strtok(":");
  418. if ($temp == "HIDE") {
  419. $conf[$n]["hide"] = 1;
  420. }
  421. else {
  422. $conf[$n]["hide"] = 0;
  423. }
  424. $temp = strtok(":");
  425. if ($temp == "VOCAB") {
  426. $conf[$n]["vocab"] = 1;
  427. }
  428. else {
  429. $conf[$n]["vocab"] = 0;
  430. }
  431. $conf[$n]["vocdb"] = "";
  432. $conf[$n]["dc"] = strtok(":");
  433. $conf[$n]["admin"] = 1;
  434. if (($conf[$n]["nick"] == "dmoclcno") || ($conf[$n]["nick"] == "fullrs")) {
  435. $conf[$n]["readonly"] = 0;
  436. $conf[$n]["req"] = 0;
  437. }
  438. else
  439. $conf[$n]["readonly"] = 1;
  440. $n++;
  441. }
  442. }
  443. }
  444. fclose($configFile);
  445. }
  446. else {
  447. $conf[$n]["name"] = "Full resolution";
  448. $conf[$n]["nick"] = "fullrs";
  449. $conf[$n]["type"] = "FULLRES";
  450. $conf[$n]["size"] = 0;
  451. $conf[$n]["find"] = "";
  452. $conf[$n]["req"] = 0;
  453. $conf[$n]["search"] = 0;
  454. $conf[$n]["hide"] = 1;
  455. $conf[$n]["vocab"] = 0;
  456. $conf[$n]["vocdb"] = "";
  457. $conf[$n]["dc"] = "";
  458. $conf[$n]["admin"] = 1;
  459. $conf[$n]["readonly"] = 0;
  460. $n++;
  461. $conf[$n]["name"] = "OCLC number";
  462. $conf[$n]["nick"] = "dmoclcno";
  463. $conf[$n]["type"] = "TEXT";
  464. $conf[$n]["size"] = 0;
  465. $conf[$n]["find"] = "";
  466. $conf[$n]["req"] = 0;
  467. $conf[$n]["search"] = 0;
  468. $conf[$n]["hide"] = 1;
  469. $conf[$n]["vocab"] = 0;
  470. $conf[$n]["vocdb"] = "";
  471. $conf[$n]["dc"] = "";
  472. $conf[$n]["admin"] = 1;
  473. $conf[$n]["readonly"] = 0;
  474. $n++;
  475. $conf[$n]["name"] = "Date created";
  476. $conf[$n]["nick"] = "dmcreated";
  477. $conf[$n]["type"] = "DATE";
  478. $conf[$n]["size"] = 0;
  479. $conf[$n]["find"] = "";
  480. $conf[$n]["req"] = 1;
  481. $conf[$n]["search"] = 0;
  482. $conf[$n]["hide"] = 1;
  483. $conf[$n]["vocab"] = 0;
  484. $conf[$n]["vocdb"] = "";
  485. $conf[$n]["dc"] = "";
  486. $conf[$n]["admin"] = 1;
  487. $conf[$n]["readonly"] = 1;
  488. $n++;
  489. $conf[$n]["name"] = "Date modified";
  490. $conf[$n]["nick"] = "dmmodified";
  491. $conf[$n]["type"] = "DATE";
  492. $conf[$n]["size"] = 0;
  493. $conf[$n]["find"] = "";
  494. $conf[$n]["req"] = 1;
  495. $conf[$n]["search"] = 0;
  496. $conf[$n]["hide"] = 1;
  497. $conf[$n]["vocab"] = 0;
  498. $conf[$n]["vocdb"] = "";
  499. $conf[$n]["dc"] = "";
  500. $conf[$n]["admin"] = 1;
  501. $conf[$n]["readonly"] = 1;
  502. $n++;
  503. $conf[$n]["name"] = "CONTENTdm number";
  504. $conf[$n]["nick"] = "dmrecord";
  505. $conf[$n]["type"] = "TEXT";
  506. $conf[$n]["size"] = 0;
  507. $conf[$n]["find"] = "";
  508. $conf[$n]["req"] = 1;
  509. $conf[$n]["search"] = 0;
  510. $conf[$n]["hide"] = 1;
  511. $conf[$n]["vocab"] = 0;
  512. $conf[$n]["vocdb"] = "";
  513. $conf[$n]["dc"] = "";
  514. $conf[$n]["admin"] = 1;
  515. $conf[$n]["readonly"] = 1;
  516. $n++;
  517. $conf[$n]["name"] = "CONTENTdm file name";
  518. $conf[$n]["nick"] = "find";
  519. $conf[$n]["type"] = "TEXT";
  520. $conf[$n]["size"] = 0;
  521. $conf[$n]["find"] = "";
  522. $conf[$n]["req"] = 1;
  523. $conf[$n]["search"] = 0;
  524. $conf[$n]["hide"] = 1;
  525. $conf[$n]["vocab"] = 0;
  526. $conf[$n]["vocdb"] = "";
  527. $conf[$n]["dc"] = "";
  528. $conf[$n]["admin"] = 1;
  529. $conf[$n]["readonly"] = 1;
  530. $n++;
  531. }
  532. return($conf);
  533. }
  534. /* Read the Dublin Core field properties */
  535. function &dmGetDublinCoreFieldInfo($lang="") {
  536. $conf = array();
  537. $n = 0;
  538. if ($lang == "")
  539. $dcfile = DC_FILE;
  540. else {
  541. $slash = getPath();
  542. $dcfile = $slash . "dc_" . $lang . ".txt";
  543. }
  544. $configFile = fopen($dcfile,"r");
  545. if (!($configFile)) {
  546. print("Error opening Dublin Core configuration file<br>\n");
  547. exit;
  548. }
  549. while (!feof($configFile)) {
  550. $s = fgets($configFile,512);
  551. if (strlen($s) > 0) {
  552. $t = substr($s,0,1);
  553. if (($t != "*") && ($t != ">") && ($t != " ")) {
  554. $conf[$n]["name"] = strtok($s,":");
  555. $conf[$n]["nick"] = strtok(":");
  556. $conf[$n]["type"] = strtok(":");
  557. $n++;
  558. }
  559. }
  560. }
  561. fclose($configFile);
  562. return($conf);
  563. }
  564. /* Read the collection full resolution settings for a given collection */
  565. function dmGetCollectionArchivalInfo($alias,&$enabled,&$public,&$volprefix,&$volsize,&$oclcsym) {
  566. $rc = dmGetCollectionParameters($alias,$name,$path);
  567. if ($rc < 0) {
  568. print("Error looking up collection $alias<br>\n");
  569. if ($rc == -1) {
  570. print("No permission to access this collection<br>\n");
  571. }
  572. exit;
  573. }
  574. $fn = $path . "/index/etc/fullconf.txt";
  575. if (file_exists($fn)) {
  576. $configFile = fopen($fn,"r");
  577. if (!($configFile)) {
  578. $enabled = 0;
  579. }
  580. else {
  581. $s = fgets($configFile,1024);
  582. $s = str_replace("\r","",$s);
  583. $s = str_replace("\n","",$s);
  584. $temp = strtok($s,":");
  585. if ($temp == "YES") {
  586. $enabled = 1;
  587. $temp = strtok(":");
  588. /*
  589. if ($temp == "PRIVATE") {
  590. $public = 0;
  591. }
  592. else {
  593. $public = 1;
  594. }
  595. */
  596. $volprefix = strtok(":");
  597. $volsize = strtok(":");
  598. $oclcsym = strtok(":");
  599. if ($oclcsym == "160x120")
  600. $oclcsym = "";
  601. }
  602. else {
  603. $enabled = 0;
  604. }
  605. fclose($configFile);
  606. }
  607. }
  608. else {
  609. $enabled = 0;
  610. }
  611. $conf = &dmGetCollectionFieldInfo($alias);
  612. $private = 1;
  613. for ($i = 0; $i < count($conf); $i++) {
  614. if ($conf[$i]["nick"] == "fullrs")
  615. $private = $conf[$i]["hide"];
  616. }
  617. if ($private == 1)
  618. $public = 0;
  619. else
  620. $public = 1;
  621. }
  622. /* Read the collection display image settings for a given collection */
  623. function dmGetCollectionDisplayImageSettings($alias,&$enabled,&$format,&$lossy,&$comptype,&$ratio,&$quality,&$tile,&$levels,&$layers,&$jpgdim,&$jpgquality) {
  624. $rc = dmGetCollectionParameters($alias,$name,$path);
  625. if ($rc < 0) {
  626. print("Error looking up collection $alias<br>\n");
  627. if ($rc == -1) {
  628. print("No permission to access this collection<br>\n");
  629. }
  630. exit;
  631. }
  632. $fn = $path . "/index/etc/fileconf.txt";
  633. if (file_exists($fn)) {
  634. $configFile = fopen($fn,"r");
  635. if (!($configFile)) {
  636. $enabled = 0;
  637. }
  638. else {
  639. $s = fgets($configFile,1024);
  640. $s = str_replace("\r","",$s);
  641. $s = str_replace("\n","",$s);
  642. $temp = strtok($s,":");
  643. if ($temp == "YES") {
  644. $enabled = 1;
  645. $temp = strtok(":"); /* format */
  646. if ($temp == "JPEG2000") {
  647. $format = "jp2";
  648. $temp = strtok(":"); /* lossy */
  649. if ($temp == "LOSSY") {
  650. $lossy = 1;
  651. $temp = strtok(":");
  652. if ($temp == "RATIO") {
  653. $comptype = "ratio";
  654. $ratio = strtok(":");
  655. $temp = strtok(":");
  656. $quality = "";
  657. }
  658. else {
  659. $comptype = "quality";
  660. $temp = strtok(":");
  661. $ratio = "";
  662. $temp = strtok(":");
  663. if ($temp == "MIN")
  664. $quality = "Minimum";
  665. elseif ($temp == "LOW")
  666. $quality = "Low";
  667. elseif ($temp == "MED")
  668. $quality = "Medium";
  669. elseif ($temp == "HIGH")
  670. $quality = "High";
  671. else
  672. $quality = "Maximum";
  673. }
  674. }
  675. else {
  676. $lossy = 0;
  677. $temp = strtok(":");
  678. $comptype = "";
  679. $temp = strtok(":");
  680. $ratio = "";
  681. $temp = strtok(":");
  682. $quality = "";
  683. }
  684. $tile = strtok(":");
  685. $levels = strtok(":");
  686. if ($levels == "AUTO")
  687. $levels = 0;
  688. $layers = strtok(":");
  689. $jpgdim = "";
  690. $jpgquality = "";
  691. }
  692. else { /* JPEG */
  693. $format = "jpg";
  694. $jpgdim = strtok(":");
  695. $jpgquality = strtok(":");
  696. $lossy = "";
  697. $comptype = "";
  698. $ratio = "";
  699. $quality = "";
  700. $tile = "";
  701. $levels = "";
  702. $layers = "";
  703. }
  704. }
  705. else {
  706. $enabled = 0;
  707. }
  708. fclose($configFile);
  709. }
  710. }
  711. else {
  712. $enabled = 0;
  713. }
  714. }
  715. /* Read the collection full resolution settings for a given collection */
  716. function dmGetCollectionPDFInfo($alias,&$enabled,&$type,&$pagetext,&$start) {
  717. $rc = dmGetCollectionParameters($alias,$name,$path);
  718. if ($rc < 0) {
  719. print("Error looking up collection $alias<br>\n");
  720. if ($rc == -1) {
  721. print("No permission to access this collection<br>\n");
  722. }
  723. exit;
  724. }
  725. $fn = $path . "/index/etc/pdfconf.txt";
  726. if (file_exists($fn)) {
  727. $configFile = fopen($fn,"r");
  728. if (!($configFile)) {
  729. $enabled = 0;
  730. }
  731. else {
  732. $s = fgets($configFile,1024);
  733. $s = str_replace("\r","",$s);
  734. $s = str_replace("\n","",$s);
  735. if ($s == "YES") {
  736. $enabled = 1;
  737. $type = "page";
  738. $pagetext = "Page";
  739. $start = 1;
  740. }
  741. elseif ($s == "NO") {
  742. $enabled = 0;
  743. }
  744. else {
  745. $temp = strtok($s,":");
  746. if ($temp == "YES") {
  747. $enabled = 1;
  748. $temp = strtok(":");
  749. if ($temp == "FILE") {
  750. $type = "file";
  751. }
  752. else {
  753. $type = "page";
  754. }
  755. $pagetext = strtok(":");
  756. if ($type == "file")
  757. $pagetext = "";
  758. $start1 = strtok(":");
  759. $start2 = strtok(":");
  760. if ($type == "page")
  761. $start = $start1;
  762. else
  763. $start = $start2;
  764. }
  765. else {
  766. $enabled = 0;
  767. }
  768. }
  769. fclose($configFile);
  770. }
  771. }
  772. else {
  773. $enabled = 0;
  774. }
  775. }
  776. /* Read the collection full resolution settings for a given collection */
  777. function dmGetCollectionFullResInfo($alias,&$enabled,&$public,&$volprefix,&$volsize,&$displaysize,&$archivesize) {
  778. $rc = dmGetCollectionParameters($alias,$name,$path);
  779. if ($rc < 0) {
  780. print("Error looking up collection $alias<br>\n");
  781. if ($rc == -1) {
  782. print("No permission to access this collection<br>\n");
  783. }
  784. exit;
  785. }
  786. $fn = $path . "/index/etc/fullconf.txt";
  787. if (file_exists($fn)) {
  788. $configFile = fopen($fn,"r");
  789. if (!($configFile)) {
  790. $enabled = 0;
  791. }
  792. else {
  793. /* Read the collections from the catalog line by line */
  794. $s = fgets($configFile,512);
  795. $s = str_replace("\r","",$s);
  796. $s = str_replace("\n","",$s);
  797. $temp = strtok($s,":");
  798. if ($temp == "YES") {
  799. $enabled = 1;
  800. $temp = strtok(":");
  801. /*
  802. if ($temp == "PRIVATE") {
  803. $public = 0;
  804. }
  805. else {
  806. $public = 1;
  807. }
  808. */
  809. $volprefix = strtok(":");
  810. $volsize = strtok(":");
  811. $temp = strtok(":");
  812. $displaysize = strtok(":");
  813. $archivesize = strtok(":");
  814. }
  815. else {
  816. $enabled = 0;
  817. }
  818. fclose($configFile);
  819. }
  820. }
  821. else {
  822. $enabled = 0;
  823. }
  824. $conf = &dmGetCollectionFieldInfo($alias);
  825. $private = 1;
  826. for ($i = 0; $i < count($conf); $i++) {
  827. if ($conf[$i]["nick"] == "fullrs")
  828. $private = $conf[$i]["hide"];
  829. }
  830. if ($private == 1)
  831. $public = 0;
  832. else
  833. $public = 1;
  834. }
  835. /* Read the collection parameters for a given collection */
  836. function dmGetCollectionFullResVolumeInfo($alias,$volname,&$location) {
  837. $rc = dmGetCollectionParameters($alias,$name,$path);
  838. if ($rc < 0) {
  839. print("Error looking up collection $alias<br>\n");
  840. if ($rc == -1) {
  841. print("No permission to access this collection<br>\n");
  842. }
  843. exit;
  844. }
  845. $fn = $path . "/index/etc/fullvol.txt";
  846. $volFile = fopen($fn,"r");
  847. if (!($volFile)) {
  848. $location = "";
  849. }
  850. else {
  851. $location = "";
  852. /* Read the volume info from the file line by line */
  853. while (!feof($volFile)) {
  854. $s = fgets($volFile,512);
  855. $temp = strtok($s,"\t");
  856. if ($temp == $volname) {
  857. $temp = strtok("\t"); /* skip volsize */
  858. $location = strtok("\t");
  859. $location = str_replace("\r","",$location);
  860. $location = str_replace("\n","",$location);
  861. break;
  862. }
  863. }
  864. fclose($volFile);
  865. }
  866. }
  867. /* Read the field vocabulary */
  868. function &dmGetCollectionFieldVocabulary($alias,$nick,$forcedict,$forcefullvoc) {
  869. $rc = dmGetCollectionParameters($alias,$name,$path);
  870. if ($rc < 0) {
  871. print("Error looking up collection $alias<br>\n");
  872. if ($rc == -1) {
  873. print("No permission to access this collection<br>\n");
  874. }
  875. exit;
  876. }
  877. if ($forcedict) {
  878. $vocabsetting = 0;
  879. }
  880. else {
  881. $conf = &dmGetCollectionFieldInfo($alias);
  882. $vocabsetting = 0;
  883. for ($i = 0; $i < count($conf); $i++) {
  884. if ($conf[$i]["nick"] == $nick) {
  885. $vocabsetting = $conf[$i]["vocab"];
  886. break;
  887. }
  888. }
  889. }
  890. $voc = array();
  891. $n = 0;
  892. if ($vocabsetting == 1) { /* return the controlled vocabulary */
  893. if ($forcefullvoc) {
  894. $mapfn = $path . "/index/vocab/" . $nick . ".map";
  895. if (file_exists($mapfn)) {
  896. $mapFile = fopen($mapfn,"r");
  897. if (!($mapFile)) {
  898. $fn = $path . "/index/vocab/" . $nick . ".txt";
  899. }
  900. else {
  901. $s = fgets($mapFile,10);
  902. fclose($mapFile);
  903. $id = trim($s);
  904. $fn = CONF_DIR . "/vocab/" . $id . ".txt";
  905. }
  906. }
  907. else
  908. $fn = $path . "/index/vocab/" . $nick . ".txt";
  909. }
  910. else {
  911. $fn = $path . "/index/text_search/voc." . $nick;
  912. }
  913. $vocFile = fopen($fn,"r");
  914. if ($vocFile) {
  915. while (!feof($vocFile)) {
  916. $s = fgets($vocFile,512);
  917. $s = str_replace("\r","",$s);
  918. $s = str_replace("\n","",$s);
  919. $base = explode("\t",$s);
  920. $s = trim($base[0]);
  921. if (strlen($s) > 0) {
  922. $voc[$n] = $s;
  923. $n++;
  924. }
  925. }
  926. fclose($vocFile);
  927. }
  928. }
  929. else { /* return the field dictionary */
  930. $fn = $path . "/index/text_search/words." . $nick;
  931. if (file_exists($fn)) {
  932. $wordFile = fopen($fn,"r");
  933. if ($wordFile) {
  934. while (!feof($wordFile)) {
  935. $s = fgets($wordFile,512);
  936. $s = str_replace("\r","",$s);
  937. $s = str_replace("\n","",$s);
  938. $base = explode("\t",$s);
  939. $s = trim($base[0]);
  940. if (strlen($s) > 0) {
  941. $voc[$n] = $s;
  942. $n++;
  943. }
  944. }
  945. }
  946. }
  947. else {
  948. $fn = $path . "/index/text_search/word." . $nick;
  949. $t = "";
  950. if (file_exists($fn)) {
  951. $wordFile = fopen($fn,"r");
  952. if ($wordFile) {
  953. while (!feof($wordFile)) {
  954. $s = fgetc($wordFile);
  955. if ($s == " ") {
  956. $voc[$n] = $t;
  957. $n++;
  958. for ($i = 0; $i < 4; $i++) {
  959. $s = fgetc($wordFile);
  960. }
  961. $t = "";
  962. }
  963. else {
  964. $t = $t . $s;
  965. }
  966. }
  967. fclose($wordFile);
  968. }
  969. }
  970. }
  971. }
  972. return($voc);
  973. }
  974. /* Read the image settings */
  975. function dmGetCollectionImageSettings($alias,&$enabled,&$minjpegdim,&$zoomlevels,&$maxderivedimg,&$viewer,&$docviewer,&$compareviewer,&$slideshowviewer) {
  976. $rc = dmGetCollectionParameters($alias,$name,$path);
  977. if ($rc < 0) {
  978. print("Error looking up collection $alias<br>\n");
  979. if ($rc == -1) {
  980. print("No permission to access this collection<br>\n");
  981. }
  982. exit;
  983. }
  984. $fn = $path . "/index/etc/imageconf.txt";
  985. if (file_exists($fn)) { /* try local collection file first */
  986. $configFile = fopen($fn,"r");
  987. }
  988. else { /* open global file */
  989. $configFile = fopen(IMAGE_FILE,"r");
  990. }
  991. if (!($configFile)) {
  992. $enabled = 0;
  993. }
  994. else {
  995. $enabled = 0;
  996. $maxderivedimg = array();
  997. $viewer = array();
  998. $docviewer = array();
  999. $compareviewer = array();
  1000. $slideshowviewer = array();
  1001. $zoomlevels = array();
  1002. $viewer["thumbnail"] = 0;
  1003. $docviewer["thumbnail"] = 0;
  1004. $compareviewer["thumbnail"] = 0;
  1005. $slideshowviewer["thumbnail"] = 0;
  1006. while (!feof($configFile)) {
  1007. $s = fgets($configFile,512);
  1008. $s = str_replace("\r","",$s);
  1009. $s = str_replace("\n","",$s);
  1010. if (strlen($s) > 0) {
  1011. if (substr($s,0,1) != "#") {
  1012. if (substr($s,0,17) == "EnableImageViewer") {
  1013. $temp = TrimValue($s,18);
  1014. if (strcasecmp($temp,"Yes") == 0) {
  1015. $enabled = 1;
  1016. }
  1017. }
  1018. elseif (substr($s,0,16) == "MinJPEGDimension") {
  1019. $minjpegdim = TrimValue($s,17);
  1020. }
  1021. elseif (substr($s,0,20) == "MaxDerivedImageWidth") {
  1022. $maxderivedimg["width"] = TrimValue($s,21);
  1023. }
  1024. elseif (substr($s,0,21) == "MaxDerivedImageHeight") {
  1025. $maxderivedimg["height"] = TrimValue($s,22);
  1026. }
  1027. elseif (substr($s,0,10) == "ZoomLevels") {
  1028. $temp = TrimValue($s,11);
  1029. $temp = $temp . " ";
  1030. $len = strlen($temp);
  1031. $start = 0;
  1032. $n = 0;
  1033. while ($start < $len) { /* parse out the zoom levels */
  1034. $p = strpos($temp," ",$start);
  1035. if ($p > 0) {
  1036. $val = substr($temp,$start,$p-$start);
  1037. if (strlen($val) > 0) {
  1038. $zoomlevels[$n] = $val;
  1039. $n++;
  1040. }
  1041. }
  1042. else {
  1043. break;
  1044. }
  1045. $start = $p + 1;
  1046. }
  1047. }
  1048. elseif (substr($s,0,11) == "ViewerWidth") {
  1049. $viewer["width"] = TrimValue($s,12);
  1050. }
  1051. elseif (substr($s,0,12) == "ViewerHeight") {
  1052. $viewer["height"] = TrimValue($s,13);
  1053. }
  1054. elseif (substr($s,0,18) == "ViewerDefaultScale") {
  1055. $viewer["scale"] = TrimValue($s,19);
  1056. }
  1057. elseif (substr($s,0,22) == "ViewerDefaultThumbnail") {
  1058. $temp = TrimValue($s,23);
  1059. if (($temp == "On") || ($temp == "ON"))
  1060. $viewer["thumbnail"] = 1;
  1061. }
  1062. elseif (substr($s,0,14) == "DocViewerWidth") {
  1063. $docviewer["width"] = TrimValue($s,15);
  1064. }
  1065. elseif (substr($s,0,15) == "DocViewerHeight") {
  1066. $docviewer["height"] = TrimValue($s,16);
  1067. }
  1068. elseif (substr($s,0,21) == "DocViewerDefaultScale") {
  1069. $docviewer["scale"] = TrimValue($s,22);
  1070. }
  1071. elseif (substr($s,0,25) == "DocViewerDefaultThumbnail") {
  1072. $temp = TrimValue($s,26);
  1073. if (($temp == "On") || ($temp == "ON"))
  1074. $docviewer["thumbnail"] = 1;
  1075. }
  1076. elseif (substr($s,0,20) == "DocViewerNoMenuWidth") {
  1077. $docviewer["nomenuwidth"] = TrimValue($s,21);
  1078. }
  1079. elseif (substr($s,0,21) == "DocViewerNoMenuHeight") {
  1080. $docviewer["nomenuheight"] = TrimValue($s,22);
  1081. }
  1082. elseif (substr($s,0,27) == "DocViewerNoMenuDefaultScale") {
  1083. $docviewer["nomenuscale"] = TrimValue($s,28);
  1084. }
  1085. elseif (substr($s,0,18) == "CompareViewerWidth") {
  1086. $compareviewer["width"] = TrimValue($s,19);
  1087. }
  1088. elseif (substr($s,0,19) == "CompareViewerHeight") {
  1089. $compareviewer["height"] = TrimValue($s,20);
  1090. }
  1091. elseif (substr($s,0,25) == "CompareViewerDefaultScale") {
  1092. $compareviewer["scale"] = TrimValue($s,26);
  1093. }
  1094. elseif (substr($s,0,29) == "CompareViewerDefaultThumbnail") {
  1095. $temp = TrimValue($s,30);
  1096. if (($temp == "On") || ($temp == "ON"))
  1097. $compareviewer["thumbnail"] = 1;
  1098. }
  1099. elseif (substr($s,0,20) == "SlideshowViewerWidth") {
  1100. $slideshowviewer["width"] = TrimValue($s,21);
  1101. }
  1102. elseif (substr($s,0,21) == "SlideshowViewerHeight") {
  1103. $slideshowviewer["height"] = TrimValue($s,22);
  1104. }
  1105. elseif (substr($s,0,27) == "SlideshowViewerDefaultScale") {
  1106. $slideshowviewer["scale"] = TrimValue($s,28);
  1107. }
  1108. elseif (substr($s,0,31) == "SlideshowViewerDefaultThumbnail") {
  1109. $temp = TrimValue($s,32);
  1110. if (($temp == "On") || ($temp == "ON"))
  1111. $slideshowviewer["thumbnail"] = 1;
  1112. }
  1113. }
  1114. }
  1115. }
  1116. if (!array_key_exists("nomenuwidth",$docviewer))
  1117. $docviewer['nomenuwidth'] = $docviewer['width'];
  1118. if (!array_key_exists("nomenuheight",$docviewer))
  1119. $docviewer['nomenuheight'] = $docviewer['height'];
  1120. if (!array_key_exists("nomenuscale",$docviewer))
  1121. $docviewer['nomenuscale'] = $docviewer['scale'];
  1122. fclose($configFile);
  1123. }
  1124. }
  1125. /* Strip off leading and trailing whitespace and trailing comment */
  1126. function TrimValue($s,$i) {
  1127. $temp = trim(substr($s,$i));
  1128. $p = strpos($temp,";");
  1129. if ($p > 0) {
  1130. $temp = trim(substr($temp,0,$p-1));
  1131. }
  1132. return($temp);
  1133. }
  1134. /* Read the item metadata */
  1135. /* Returns: -1 = no permission, 1 = full access, 2 = metadata only */
  1136. function dmGetItemInfo($alias,$ptr,&$xmlbuffer) {
  1137. global $items;
  1138. $xmlbuffer = $items["$alias/$ptr"];
  1139. return($rc);
  1140. }
  1141. /* Read the metadata file */
  1142. /* Returns: -1 = no permission, 1 = full access, 2 = metadata only */
  1143. function ReadItemDesc($path,$ptr,&$xmlbuffer) {
  1144. if (!extension_loaded('dmopr')) {
  1145. if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
  1146. dl('php_dmoprmod.dll');
  1147. }
  1148. else {
  1149. dl('dmopr.so');
  1150. }
  1151. }
  1152. $oprarg = "getdesc " . $path . "|" . $ptr;
  1153. $buf2 = dmopr($oprarg);
  1154. $xmlbuffer = $buf2;
  1155. $itemperm = GetXMLField("dmaccess",$xmlbuffer);
  1156. if ($itemperm != "") {
  1157. $rc = CheckUser($itemperm);
  1158. if ($rc == 0) {
  1159. $xmlbuffer = "";
  1160. }
  1161. }
  1162. else {
  1163. $rc = 1;
  1164. }
  1165. if ($xmlbuffer == "") {
  1166. return(-1);
  1167. }
  1168. else {
  1169. return($rc);
  1170. }
  1171. }
  1172. /* Read the compound object structure information */
  1173. function dmGetCompoundObjectInfo($alias,$ptr,&$xmlbuffer) {
  1174. global $compound_objects;
  1175. $xmlbuffer = $compound_objects["$alias/$ptr"];
  1176. return(0);
  1177. }
  1178. /* Read the image size */
  1179. function dmGetImageInfo($alias,$ptr,&$filename,&$type,&$width,&$height) {
  1180. $rc = dmGetCollectionParameters($alias,$name,$path);
  1181. if ($rc < 0) {
  1182. return(-1); /* no collection permission */
  1183. }
  1184. $rc = ReadItemDesc($path,$ptr,$data);
  1185. if ($rc == -1) {
  1186. return(-1);
  1187. }
  1188. /* FIX to decode ampersands in filenames */
  1189. $findval = str_replace("&amp;","&",GetXMLField("find",$data));
  1190. $filename = trim($path . "/image/" . $findval);
  1191. $ext = GetFileExt($filename);
  1192. if (($ext == "jpg") || ($ext == "gif") || ($ext == "png") || ($ext == "jp2") || ($ext == "tif") || ($ext == "tiff")) {
  1193. $type = $ext;
  1194. $size = GetImageDimensions($filename);
  1195. $width = $size["width"];
  1196. $height = $size["height"];
  1197. }
  1198. elseif ($ext == "url") {
  1199. $type = "";
  1200. $width = 0;
  1201. $height = 0;
  1202. if (file_exists($filename)) {
  1203. $urlFile = fopen($filename,"r");
  1204. $n = filesize($filename);
  1205. $urlbuffer = fread($urlFile,$n);
  1206. fclose($urlFile);
  1207. if (strstr($urlbuffer,"about:blank"))
  1208. $type = "null";
  1209. }
  1210. }
  1211. else {
  1212. $type = "";
  1213. $width = 0;
  1214. $height = 0;
  1215. }
  1216. }
  1217. /* Read My Favorites saved items out of the cookie */
  1218. function &dmGetFavorites($field) {
  1219. $record = array();
  1220. $pathmap = array();
  1221. $n = 0;
  1222. if (isset($_COOKIE['BUF'])) {
  1223. $temp = $_COOKIE['BUF'];
  1224. $catlist = &dmGetCollectionList();
  1225. for ($i = 0; $i < count($catlist); $i++) {
  1226. $pathmap[$catlist[$i]["alias"]] = $catlist[$i]["path"];
  1227. }
  1228. /* Parse the cookie data */
  1229. $len = strlen($temp);
  1230. $start = 0;
  1231. $n = 0;
  1232. while ($start < $len) { /* parse out the zoom levels */
  1233. $p = strpos($temp,">",$start);
  1234. if ($p > 0) {
  1235. $val = substr($temp,$start,$p-$start);
  1236. $l = strlen($val);
  1237. if ($l > 4) {
  1238. $q = strpos($val,"<",0);
  1239. if ($q > 0) {
  1240. $ptr = substr($val,$q+1,$l-$q);
  1241. $alias = substr($val,0,$q);
  1242. if (array_key_exists($alias,$pathmap)) {
  1243. $rc = dmGetItemInfo($alias,$ptr,$data);
  1244. if ($rc >= 0) {
  1245. $record[$n]["collection"] = $alias;
  1246. $record[$n]["pointer"] = $ptr;
  1247. if(!($parser = xml_parser_create()))
  1248. {
  1249. print("Error creating XML parser<br>");
  1250. exit();
  1251. }
  1252. xml_parse_into_struct($parser, $data, $structure, $index);
  1253. xml_parser_free($parser);
  1254. /* Read the filetype */
  1255. if (array_key_exists("value",$structure[$index["FIND"][0]]))
  1256. $record[$n]["filetype"] = GetFileExt($structure[$index["FIND"][0]]["value"]);
  1257. else
  1258. $record[$n]["filetype"] = "";
  1259. $record[$n]["parentobject"] = GetParent($record[$n]["collection"],$record[$n]["pointer"],$pathmap[$record[$n]["collection"]]);
  1260. /* Read any metadata fields to pass back */
  1261. for ($j = 0; $j < count($field); $j++) {
  1262. $tag = strtoupper($field[$j]);
  1263. if (array_key_exists($tag,$index)) {
  1264. if (array_key_exists("value",$structure[$index[$tag][0]]))
  1265. $record[$n][$field[$j]] = $structure[$index[$tag][0]]["value"];
  1266. else
  1267. $record[$n][$field[$j]] = "";
  1268. }
  1269. else {
  1270. $record[$n][$field[$j]] = "";
  1271. }
  1272. }
  1273. $n++;
  1274. }
  1275. }
  1276. }
  1277. }
  1278. }
  1279. else {
  1280. break;
  1281. }
  1282. $start = $p + 1;
  1283. }
  1284. }
  1285. return($record);
  1286. }
  1287. /* Parse the favorites out of the cookie string */
  1288. function ParseFavorites($str,&$record) {
  1289. /* Parse the cookie data */
  1290. $len = strlen($str);
  1291. $start = 0;
  1292. $n = 0;
  1293. while ($start < $len) { /* parse out the records */
  1294. $p = strpos($str,">",$start);
  1295. if ($p > 0) {
  1296. $val = substr($str,$start,$p-$start);
  1297. $l = strlen($val);
  1298. if ($l > 4) {
  1299. $q = strpos($val,"<",0);
  1300. if ($q > 0) {
  1301. $ptr = substr($val,$q+1,$l-$q);
  1302. $alias = substr($val,0,$q);
  1303. $record[$n]["collection"] = $alias;
  1304. $record[$n]["pointer"] = $ptr;
  1305. if ($n < MAX_FAVORITES) {
  1306. $n++;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else {
  1312. break;
  1313. }
  1314. $start = $p + 1;
  1315. }
  1316. }
  1317. /* Add item(s) to My Favorites */
  1318. function dmAddFavorite($record) {
  1319. if (isset($_COOKIE['BUF'])) {
  1320. $s = $_COOKIE['BUF'];
  1321. }
  1322. else {
  1323. $s = "";
  1324. }
  1325. $n = 0;
  1326. for ($i = 0; $i < strlen($s); $i++) {
  1327. if ($s{$i} == '>') {
  1328. $n++;
  1329. }
  1330. }
  1331. for ($i = 0; $i < count($record); $i++) {
  1332. $t = $record[$i]["collection"] . "<" . $record[$i]["pointer"] . ">";
  1333. if (strstr($s,$t) == "") {
  1334. if ($n < MAX_FAVORITES) {
  1335. $s = $s . $t;
  1336. }
  1337. }
  1338. }
  1339. /* Set the cookie */
  1340. header("Set-Cookie: BUF=$s; path=/; expires=Saturday, 19-Nov-2011 12:00:00 GMT");
  1341. }
  1342. /* Delete item(s) from My Favorites */
  1343. function dmDeleteFavorite($record) {
  1344. if (isset($_COOKIE['BUF'])) {
  1345. $s = $_COOKIE['BUF'];
  1346. }
  1347. else {
  1348. $s = "";
  1349. }
  1350. $buf = array();
  1351. ParseFavorites($s,$buf);
  1352. $cookieval = "";
  1353. for ($i = 0; $i < count($buf); $i++) {
  1354. $found = 0;
  1355. for ($j = 0; $j < count($record); $j++) {
  1356. if ($i == ($record[$j]-1)) {
  1357. $found = 1;
  1358. break;
  1359. }
  1360. }
  1361. if ($found == 0) {
  1362. $cookieval = $cookieval . $buf[$i]["collection"] . "<" . $buf[$i]["pointer"] . ">";
  1363. }
  1364. }
  1365. /* Set the cookie */
  1366. header("Set-Cookie: BUF=$cookieval; path=/; expires=Saturday, 19-Nov-2011 12:00:00 GMT");
  1367. }
  1368. /* Move items in My Favorites */
  1369. function dmMoveFavorite($from,$to) {
  1370. if (isset($_COOKIE['BUF'])) {
  1371. $s = $_COOKIE['BUF'];
  1372. }
  1373. else {
  1374. $s = "";
  1375. }
  1376. $buf = array();
  1377. ParseFavorites($s,$buf);
  1378. $n = count($buf);
  1379. /* Check that the arguments are legal */
  1380. if (($from > 0) && ($from <= $n) && ($to > 0) && ($to <= $n) && ($from != $to)) {
  1381. $from = $from - 1;
  1382. $to = $to - 1;
  1383. if ($from < $to) {
  1384. $tempcol = $buf[$from]["collection"];
  1385. $tempptr = $buf[$from]["pointer"];
  1386. for ($i = $from; $i < $to; $i++) {
  1387. $buf[$i]["collection"] = $buf[$i+1]["collection"];
  1388. $buf[$i]["pointer"] = $buf[$i+1]["pointer"];
  1389. }
  1390. $buf[$to]["collection"] = $tempcol;
  1391. $buf[$to]["pointer"] = $tempptr;
  1392. }
  1393. else {
  1394. $tempcol = $buf[$from]["collection"];
  1395. $tempptr = $buf[$from]["pointer"];
  1396. for ($i = $from; $i > $to; $i--) {
  1397. $buf[$i]["collection"] = $buf[$i-1]["collection"];
  1398. $buf[$i]["pointer"] = $buf[$i-1]["pointer"];
  1399. }
  1400. $buf[$to]["collection"] = $tempcol;
  1401. $buf[$to]["pointer"] = $tempptr;
  1402. }
  1403. $cookieval = "";
  1404. for ($i = 0; $i < $n; $i++) {
  1405. $cookieval = $cookieval . $buf[$i]["collection"] . "<" . $buf[$i]["pointer"] . ">";
  1406. }
  1407. /* Set the cookie */
  1408. header("Set-Cookie: BUF=$cookieval; path=/; expires=Saturday, 19-Nov-2011 12:00:00 GMT");
  1409. }
  1410. }
  1411. /* Perform a text query */
  1412. function &dmQuery($alias,$searchstring,$field,$sortby,$maxrecs,$start,&$total,$suppress=0,$docptr=-1,&$suggest=0,&$facet="") {
  1413. $record = array();
  1414. $pathmap = array();
  1415. $n = 0;
  1416. $numsearchfields = count($searchstring);
  1417. if (($numsearchfields == 0) && (count($alias) != 1)) { /* can only browse one collection */
  1418. $total = 0;
  1419. }
  1420. else {
  1421. if (count($alias) == 0) {
  1422. print("Error, no collections specified<br>\n");
  1423. exit;
  1424. }
  1425. $catlist = &dmGetCollectionList();
  1426. for ($i = 0; $i < count($catlist); $i++) {
  1427. $pathmap[$catlist[$i]["alias"]] = $catlist[$i]["path"];
  1428. }
  1429. if (($alias[0] == "all") || ((count($alias) == count($catlist)) && (count($catlist) > 1))) {
  1430. $n = GetCatalogCount();
  1431. if (count($catlist) == $n)
  1432. $dblist = "/";
  1433. else {
  1434. $dblist = $catlist[0]["alias"];
  1435. for ($i = 1; $i < count($catlist); $i++) {
  1436. $dblist = $dblist . "," . $catlist[$i]["alias"];
  1437. }
  1438. }
  1439. }
  1440. else {
  1441. $dblist = $alias[0];
  1442. for ($i = 1; $i < count($alias); $i++) {
  1443. $dblist = $dblist . "," . $alias[$i];
  1444. }
  1445. }
  1446. if (count($sortby) == 0) {
  1447. $sortlist = "";
  1448. }
  1449. else {
  1450. $sortlist = $sortby[0];
  1451. for ($i = 1; $i < count($sortby); $i++) {
  1452. $sortlist = $sortlist . " " . $sortby[$i];
  1453. }
  1454. }
  1455. if (($alias[0] == "all") || (count($alias) > 1))
  1456. $temp = "dc";
  1457. else
  1458. $temp = $alias[0];
  1459. $findmap = dmGetFindNick($temp);
  1460. for ($i = 0; $i < 6; $i++) {
  1461. $fieldmap[$i] = -1;
  1462. }
  1463. $multimode = 0;
  1464. for ($i = 0; $i < $numsearchfields; $i++) {
  1465. if (trim($searchstring[$i]["string"]) != "") {
  1466. $searchstring[$i]["string"] = str_replace('"',"",$searchstring[$i]["string"]);
  1467. // $searchstring[$i]["string"] = str_replace(':'," ",$searchstring[$i]["string"]);
  1468. if ($searchstring[$i]["mode"] == "exact") {
  1469. $searchstring[$i]["string"] = str_replace("--"," -- ",$searchstring[$i]["string"]);
  1470. $fieldmap[1] = $i;
  1471. }
  1472. else {
  1473. $searchstring[$i]["string"] = str_replace("--"," - ",$searchstring[$i]["string"]);
  1474. if ($searchstring[$i]["mode"] == "all") {
  1475. $fieldmap[0] = $i;
  1476. }
  1477. elseif ($searchstring[$i]["mode"] == "any") {
  1478. $fieldmap[2] = $i;
  1479. }
  1480. elseif ($searchstring[$i]["mode"] == "none") {
  1481. $fieldmap[3] = $i;
  1482. }
  1483. }
  1484. }
  1485. }
  1486. $searchlist = "";
  1487. if ($multimode == 1) { /* Search across all fields */
  1488. if ($fieldmap[1] >= 0) {
  1489. if (!strstr($searchstring[$fieldmap[1]]["string"]," near"))
  1490. $searchlist = '"' . $searchstring[$fieldmap[1]]["string"] . '"';
  1491. else
  1492. $searchlist = $searchstring[$fieldmap[1]]["string"];
  1493. }
  1494. if ($fieldmap[0] >= 0) {
  1495. if ($searchlist != "")
  1496. $searchlist = $searchlist . " and ";
  1497. $str = str_replace('('," ",$searchstring[$fieldmap[0]]["string"]);
  1498. $str = str_replace(')'," ",$str);
  1499. $searchlist = $searchlist . AddOperator($str,"and");
  1500. }
  1501. if ($fieldmap[2] >= 0) {
  1502. $str = str_replace('('," ",$searchstring[$fieldmap[2]]["string"]);
  1503. $str = str_replace(')'," ",$str);
  1504. if ($searchlist != "") {
  1505. $searchlist = $searchlist . " and ";
  1506. $searchlist = $searchlist . "(" . AddOperator($str,"or") . ")";
  1507. }
  1508. else
  1509. $searchlist = $searchlist . AddOperator($str,"or");
  1510. }
  1511. if ($fieldmap[3] >= 0) {
  1512. if ($searchlist != "")
  1513. $searchlist = $searchlist . " not ";
  1514. else
  1515. $searchlist = "not ";
  1516. $searchlist = $searchlist . "(" . AddOperator($searchstring[$fieldmap[3]]["string"],"or") . ")";
  1517. }
  1518. }
  1519. else { /* Selected fields */
  1520. $notclause = "";
  1521. for ($i = 0; $i < $numsearchfields; $i++) {
  1522. if (trim($searchstring[$i]["string"]) != "") {
  1523. if ($i > 0)
  1524. $searchlist = $searchlist . " ";
  1525. $code = "ft";
  1526. $isdate = 0;
  1527. for ($j = 0; $j < count($findmap); $j++) {
  1528. if ($searchstring[$i]["field"] == "CISOSEARCHALL") {
  1529. $code = "ft";
  1530. $isdate = 0;
  1531. break;
  1532. }
  1533. if ($searchstring[$i]["field"] == $findmap[$j]["cdmnick"]) {
  1534. $code = $findmap[$j]["findnick"];
  1535. $isdate = $findmap[$j]["date"];
  1536. break;
  1537. }
  1538. }
  1539. if (($isdate) && (!strstr($searchstring[$i]["string"]," "))) {
  1540. $searchlist = $searchlist . "(" . $code . ":" . FormatDateString($searchstring[$i]["string"]) . ")";
  1541. }
  1542. elseif ($searchstring[$i]["mode"] == "all") {
  1543. $str = str_replace('('," ",$searchstring[$i]["string"]);
  1544. $str = str_replace(')'," ",$str);
  1545. $searchlist = $searchlist . $code . ":" . AddOperator($str,"and");
  1546. }
  1547. elseif ($searchstring[$i]["mode"] == "exact") {
  1548. if (!strstr($searchstring[$i]["string"]," near"))
  1549. $searchlist = $searchlist . $code . ":" . '"' . $searchstring[$i]["string"] . '"';
  1550. else
  1551. $searchlist = $searchlist . $code . ":" . $searchstring[$i]["string"];
  1552. }
  1553. elseif ($searchstring[$i]["mode"] == "any") {
  1554. $str = str_replace('('," ",$searchstring[$i]["string"]);
  1555. $str = str_replace(')'," ",$str);
  1556. $searchlist = $searchlist . "(" . $code . ":" . AddOperator($str,"or") . ")";
  1557. }
  1558. elseif ($searchstring[$i]["mode"] == "none") {
  1559. $notclause = $notclause . " not (" . $code . ":" . AddOperator($searchstring[$i]["string"],"or") . ")";
  1560. // $searchlist = $searchlist . "not (" . $code . ":" . AddOperator($searchstring[$i]["string"],"or") . ")";
  1561. }
  1562. }
  1563. }
  1564. if ($notclause != "") {
  1565. $searchlist = trim($searchlist) . $notclause;
  1566. }
  1567. }
  1568. if (!extension_loaded('DmSearch')) {
  1569. if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
  1570. dl('php_dmsearchmod.dll');
  1571. }
  1572. else {
  1573. dl('dmsearch.so');
  1574. }
  1575. }
  1576. $dmid = dmGetUser();
  1577. if (isset($_SERVER["REMOTE_ADDR"]))
  1578. $remote_addr = $_SERVER["REMOTE_ADDR"];
  1579. else
  1580. $remote_addr = "";
  1581. if ($suppress == 1)
  1582. $multimode = $multimode + 20;
  1583. /* browse mode */
  1584. if ($numsearchfields == 0) {
  1585. $result = dmsearch($dblist,$searchlist,$multimode,$docptr,$start,$maxrecs,$sortlist,$dmid,$remote_addr);
  1586. if (substr($result,0,1) == "0") {
  1587. $total = 0;
  1588. $n = 0;
  1589. $temp = strtok($result,"\n");
  1590. $p1 = strpos($temp," ");
  1591. if ($p1 != FALSE) {
  1592. $p2 = strpos($temp," ",$p1+1);
  1593. if ($p2 != FALSE) {
  1594. $total = (int) trim(substr($temp,$p2+1));
  1595. }
  1596. }
  1597. while (($temp = strtok("\n")) != FALSE) {
  1598. $p1 = strpos($temp," ");
  1599. $p2 = strpos($temp," ",$p1+1);
  1600. $record[$n]["collection"] = trim(substr($temp,0,$p1));
  1601. $record[$n]["pointer"] = trim(substr($temp,$p1+1,$p2-$p1-1));
  1602. $record[$n]["filetype"] = trim(substr($temp,$p2+1));
  1603. $record[$n]["parentobject"] = GetParent($record[$n]["collection"],$record[$n]["pointer"],$pathmap[$record[$n]["collection"]]);
  1604. $n++;
  1605. }
  1606. }
  1607. else { /* Error */
  1608. $total = 0;
  1609. }
  1610. }
  1611. else { /* Run the FIND search */
  1612. $searchstr = $searchlist;
  1613. $searchstr = str_replace("*","\\*",$searchstr); /* wildcard */
  1614. $searchstr = str_replace(" near"," n",$searchstr); /* proximity */
  1615. // $searchstr = str_replace('"',"",$searchstr);
  1616. // $searchstr = str_replace(" -- "," - ",$searchstr);
  1617. // $searchstr = str_replace(" --"," -",$searchstr);
  1618. if ($dblist != "/")
  1619. $dblist = str_replace(",","/,",$dblist) . "/";
  1620. $collstr = $dblist;
  1621. /* Handle the sortby, hardcoded 2-character nicknames */
  1622. if (count($sortby) == 0) {
  1623. $sortstr = "ti";
  1624. }
  1625. else {
  1626. $scount = count($sortby);
  1627. $sortstr = "";
  1628. if ($sortby[$scount-1] == "reverse")
  1629. $sortstr = "-";
  1630. $scount--;
  1631. if ($scount == 0)
  1632. $sortstr = $sortstr . "ti";
  1633. else {
  1634. $sortstr = $sortstr . substr($sortby[0],0,2);
  1635. for ($i = 1; $i < $scount; $i++)
  1636. $sortstr = $sortstr . ":" . substr($sortby[$i],0,2);
  1637. }
  1638. }
  1639. $fstart = $start - 1;
  1640. if (isset($_SERVER["REMOTE_ADDR"]))
  1641. $remote_addr = $_SERVER["REMOTE_ADDR"];
  1642. else
  1643. $remote_addr = "";
  1644. $access_str = " (za:f3";
  1645. if ($dmid != "")
  1646. $access_str = $access_str . " or \"" . $dmid . "\"";
  1647. if ($remote_addr != "")
  1648. $access_str = $access_str . " or " . $remote_addr . ")";
  1649. /* compound object search */
  1650. if ($docptr > -1) {
  1651. $searchstr = $searchstr . " cp:" . $docptr;
  1652. }
  1653. if ($suppress == 1) {
  1654. $sortstr = "";
  1655. $scount = count($sortby);
  1656. if ($scount == 0)
  1657. $sortstr = "-\$max.\$d";
  1658. else {
  1659. if ($sortby[$scount-1] == "reverse") {
  1660. $sortstr = "-";
  1661. $scount = $scount - 1;
  1662. }
  1663. for ($i = 0; $i < $scount; $i++) {
  1664. $code = LookupFindNick($findmap,$sortby[$i]);
  1665. if (($code != "") && ($code != "BLANK"))
  1666. $sortstr = $sortstr . "\$" . $code;
  1667. }
  1668. }
  1669. if (($sortstr == "") || ($sortstr == "-") || ($sortstr == "$"))
  1670. $sortstr = "-\$max.\$d";
  1671. $displaystr = "&group=\$group.pa.cp<ITEM><DB>\$pa</DB><KEY>\$cp</KEY><SORT>\$sort" . $sortstr . "</SORT></ITEM>";
  1672. }
  1673. else {
  1674. $sortstr = "";
  1675. $scount = count($sortby);
  1676. if ($scount == 0)
  1677. $sortstr = "\$density";
  1678. else {
  1679. if ($sortby[$scount-1] == "reverse") {
  1680. $sortstr = "-";
  1681. $scount = $scount - 1;
  1682. }
  1683. for ($i = 0; $i < $scount; $i++) {
  1684. $code = LookupFindNick($findmap,$sortby[$i]);
  1685. if ($i > 0)
  1686. $sortstr = $sortstr . ":";
  1687. $sortstr = $sortstr . $code;
  1688. }
  1689. }
  1690. $displaystr = "&sort=" . $sortstr . "&display=<ITEM><DB>\$\$DM_pa\$\$</DB><KEY>\$\$DM_ci\$\$</KEY></ITEM>";
  1691. }
  1692. $facetstr = "";
  1693. if ($facet != "") {
  1694. $facetnick = explode(":",$facet);
  1695. $facetcodestr = "";
  1696. for ($i = 0; $i < count($facetnick); $i++) {
  1697. $code = LookupFindNick($findmap,$facetnick[$i]);
  1698. if (($code != "") && ($code != "BLANK"))
  1699. $facetcodestr = $facetcodestr . $code . ":";
  1700. }
  1701. $facetstr = "&facet=1&maxfacet=10&rsum=" . $facetcodestr . "&facetinitial=" . $facetcodestr;
  1702. }
  1703. $findurl = ReadFindURL();
  1704. $url = $findurl . "/!/search?query=" . urlencode($searchstr) . " and" . $access_str . $displaystr . "&collection=" . $collstr . "&suggest=1" . $facetstr . "&rankboost=&proximity=strict&priority=normal&unanchoredphrases=1&maxres=" . $maxrecs . "&firstres=" . $fstart . "&rform=/!/null.htm";
  1705. print("<!-- $url //-->\n");
  1706. $result = file_get_contents($url);
  1707. $result = str_replace("&lt;","<",$result);
  1708. $istart = 0;
  1709. $n = 0;
  1710. $rc = GetField("count",$result,$buf,0);
  1711. if ($rc < -1)
  1712. $total = 0;
  1713. else
  1714. $total = $buf + 0;
  1715. while ($istart >= 0) {
  1716. $istart = GetField("ITEM",$result,$buf,$istart);
  1717. if ($istart >= 0) {
  1718. $rc = GetField("DB",$buf,$db,0);
  1719. $rc = GetField("KEY",$buf,$ptr,0);
  1720. if (($db != "") && ($ptr != "")) {
  1721. $record[$n]["collection"] = rtrim($db,"/ ");
  1722. $record[$n]["pointer"] = $ptr;
  1723. $record[$n]["filetype"] = "jpg"; /* hardcoded */
  1724. $record[$n]["parentobject"] = GetParent($record[$n]["collection"],$record[$n]["pointer"],$pathmap[$record[$n]["collection"]]);
  1725. $n++;
  1726. if ($n == $maxrecs)
  1727. break;
  1728. }
  1729. }
  1730. }
  1731. /* spelling suggestion */
  1732. if (($total == 0) && ($suggest == 1)) {
  1733. if ((!strstr($searchstr," not ")) && (!strstr($searchstr,":not "))) {
  1734. $url = $findurl . "/!/search?query=" . urlencode($searchstr) . $displaystr . "&collection=" . $collstr . "&suggest=1" . $facetstr . "&rankboost=&proximity=strict&priority=normal&unanchoredphrases=0&maxres=" . $maxrecs . "&firstres=" . $fstart . "&rform=/!/null.htm";
  1735. $result = file_get_contents($url);
  1736. $rc = GetField("alternate",$result,$temp,0);
  1737. if ($rc < -1)
  1738. $temp = "";
  1739. $suggest = trim($temp);
  1740. if ($suggest != "") {
  1741. if (substr($suggest,2,1) == ":")
  1742. $suggest = substr($suggest,3);
  1743. $p = strpos($suggest,":",0);
  1744. if ($p) {
  1745. if ($p > 1)
  1746. $suggest = trim(substr($suggest,0,$p-2));
  1747. }
  1748. }
  1749. }
  1750. else
  1751. $suggest = "";
  1752. }
  1753. /* facets */
  1754. if ($facet != "") {
  1755. $istart = 0;
  1756. $facet = "<facet>\n";
  1757. $k = 0;
  1758. $facetmap = array();
  1759. while ($istart >= 0) {
  1760. $istart = GetField("FacetItem",$result,$buf,$istart);
  1761. if ($istart >= 0) {
  1762. $rc = GetField("label",$buf,$facetlabel,0);
  1763. $rc = GetField("name",$buf,$facetname,0);
  1764. $rc = GetField("count",$buf,$facetcount,0);
  1765. if (($facetlabel != "") && ($facetname != "") && ($facetcount != "")) {
  1766. $code = substr(trim($facetlabel),0,2);
  1767. $label = "";
  1768. for ($j = 0; $j < count($findmap); $j++) {
  1769. if ($code == $findmap[$j]["findnick"]) {
  1770. $label = $findmap[$j]["cdmnick"];
  1771. break;
  1772. }
  1773. }
  1774. $facetmap[$k]["label"] = $label;
  1775. $facetmap[$k]["name"] = $facetname;
  1776. $facetmap[$k]["count"] = (int) $facetcount;
  1777. $k++;
  1778. }
  1779. }
  1780. }
  1781. for ($i = 0; $i < $k-1; $i++) {
  1782. for ($j = $i+1; $j < $k; $j++) {
  1783. if (($facetmap[$i]["label"] == $facetmap[$j]["label"]) && ($facetmap[$i]["name"] == $facetmap[$j]["name"])) {
  1784. $facetmap[$i]["count"] = $facetmap[$i]["count"] + $facetmap[$j]["count"];
  1785. $facetmap[$j]["count"] = 0;
  1786. }
  1787. }
  1788. }
  1789. for ($i = 0; $i < $k-1; $i++) {
  1790. for ($j = $i+1; $j < $k; $j++) {
  1791. if ($facetmap[$i]["count"] < $facetmap[$j]["count"]) {
  1792. $label = $facetmap[$i]["label"];
  1793. $facetname = $facetmap[$i]["name"];
  1794. $facetcount = $facetmap[$i]["count"];
  1795. $facetmap[$i]["label"] = $facetmap[$j]["label"];
  1796. $facetmap[$i]["name"] = $facetmap[$j]["name"];
  1797. $facetmap[$i]["count"] = $facetmap[$j]["count"];
  1798. $facetmap[$j]["label"] = $label;
  1799. $facetmap[$j]["name"] = $facetname;
  1800. $facetmap[$j]["count"] = $facetcount;
  1801. }
  1802. }
  1803. }
  1804. for ($j = 0; $j < $k; $j++) {
  1805. if ($facetmap[$j]["count"] > 0)
  1806. $facet = $facet . " <label>" . $facetmap[$j]["label"] . "</label><name>" . $facetmap[$j]["name"] . "</name><count>" . $facetmap[$j]["count"] . "</count>\n";
  1807. }
  1808. $facet = $facet . "</facet>\n";
  1809. }
  1810. }
  1811. }
  1812. /* Check if there are any metadata fields to return */
  1813. if (count($field) > 0) {
  1814. for ($i = 0; $i < count($record); $i++) {
  1815. dmGetItemInfo($record[$i]["collection"],$record[$i]["pointer"],$data);
  1816. if(!($parser = xml_parser_create()))
  1817. {
  1818. print("Error creating XML parser<br>");
  1819. exit();
  1820. }
  1821. xml_parse_into_struct($parser, $data, $structure, $index);
  1822. xml_parser_free($parser);
  1823. for ($j = 0; $j < count($field); $j++) {
  1824. $tag = strtoupper($field[$j]);
  1825. if (array_key_exists($tag,$index)) {
  1826. if (array_key_exists("value",$structure[$index[$tag][0]])) {
  1827. $record[$i][$field[$j]] = $structure[$index[$tag][0]]["value"];
  1828. }
  1829. else {
  1830. $record[$i][$field[$j]] = "";
  1831. }
  1832. }
  1833. else {
  1834. $record[$i][$field[$j]] = "";
  1835. }
  1836. }
  1837. /* Get the file extension for Find */
  1838. if (array_key_exists("FIND",$index)) {
  1839. if (array_key_exists("value",$structure[$index["FIND"][0]])) {
  1840. $temp = $structure[$index["FIND"][0]]["value"];
  1841. $record[$i]["filetype"] = GetFileExt($temp);
  1842. }
  1843. }
  1844. }
  1845. }
  1846. return($record);
  1847. }
  1848. /* Read the Find nicknames */
  1849. function &dmGetFindNick($alias) {
  1850. $res = array();
  1851. $n = 0;
  1852. if ($alias == "dc") {
  1853. $infile = FIND_DIR . "/config/finddc.txt";
  1854. if (file_exists($infile)) {
  1855. $fd = fopen($infile,"r");
  1856. if ($fd) {
  1857. while (!feof($fd)) {
  1858. $t = fgets($fd,2048);
  1859. $s = explode(" ",$t);
  1860. $j = count($s);
  1861. if ($j > 1) {
  1862. $left = strtolower(trim($s[0]));
  1863. $right = trim($s[$j-1]);
  1864. if ($left == "collection")
  1865. continue;
  1866. if ($left == "cdmid")
  1867. break;
  1868. $res[$n]["findnick"] = $left;
  1869. $res[$n]["cdmnick"] = $right;
  1870. if (substr($right,0,4) == "date")
  1871. $res[$n]["date"] = 1;
  1872. else
  1873. $res[$n]["date"] = 0;
  1874. $n++;
  1875. }
  1876. }
  1877. }
  1878. }
  1879. fclose($fd);
  1880. }
  1881. else {
  1882. $conf = &dmGetCollectionFieldInfo($alias);
  1883. for ($i = 0; $i < count($conf); $i++) {
  1884. if ($conf[$i]["search"] == 1) {
  1885. $res[$n]["findnick"] = $conf[$i]["find"];
  1886. $res[$n]["cdmnick"] = $conf[$i]["nick"];
  1887. if ($conf[$i]["type"] == "DATE")
  1888. $res[$n]["date"] = 1;
  1889. else
  1890. $res[$n]["date"] = 0;
  1891. $n++;
  1892. }
  1893. }
  1894. }
  1895. return($res);
  1896. }
  1897. function LookupFindNick($findmap,$field) {
  1898. $code = "";
  1899. for ($i = 0; $i < count($findmap); $i++) {
  1900. if ($findmap[$i]["cdmnick"] == $field) {
  1901. $code = $findmap[$i]["findnick"];
  1902. break;
  1903. }
  1904. }
  1905. return($code);
  1906. }
  1907. /* Return the XML field */
  1908. function GetField($tag,$xmlbuffer,&$s,$start) {
  1909. $tagstart = "<" . $tag . ">";
  1910. $tagend = "</" . $tag . ">";
  1911. $p1 = strpos($xmlbuffer,$tagstart,$start);
  1912. $p2 = strpos($xmlbuffer,$tagend,$start);
  1913. if (($p1 === FALSE) || ($p2 === FALSE) || ($p2 < $p1)) {
  1914. $s = "";
  1915. return(-1);
  1916. }
  1917. $l = strlen($tagstart);
  1918. if (($p1 + $l) == $p2) {
  1919. $s = "";
  1920. return(-1);
  1921. }
  1922. $s = substr($xmlbuffer,$p1+$l,$p2-$p1-$l);
  1923. return($p2+strlen($tagend));
  1924. }
  1925. /* Perform a text query */
  1926. function &dmQuery43($alias,$searchstring,$field,$sortby,$maxrecs,$start,&$total,$suppress=0,$docptr=-1) {
  1927. $record = array();
  1928. $pathmap = array();
  1929. $n = 0;
  1930. $numsearchfields = count($searchstring);
  1931. if (($numsearchfields == 0) && (count($alias) != 1)) { /* can only browse one collection */
  1932. $total = 0;
  1933. }
  1934. else {
  1935. if (count($alias) == 0) {
  1936. print("Error, no collections specified<br>\n");
  1937. exit;
  1938. }
  1939. $catlist = &dmGetCollectionList();
  1940. for ($i = 0; $i < count($catlist); $i++) {
  1941. $pathmap[$catlist[$i]["alias"]] = $catlist[$i]["path"];
  1942. }
  1943. if ($alias[0] == "all") {
  1944. $dblist = $catlist[0]["alias"];
  1945. for ($i = 1; $i < count($catlist); $i++) {
  1946. $dblist = $dblist . " " . $catlist[$i]["alias"];
  1947. }
  1948. }
  1949. else {
  1950. $dblist = $alias[0];
  1951. for ($i = 1; $i < count($alias); $i++) {
  1952. $dblist = $dblist . " " . $alias[$i];
  1953. }
  1954. }
  1955. if (count($sortby) == 0) {
  1956. $sortlist = "";
  1957. }
  1958. else {
  1959. $sortlist = $sortby[0];
  1960. for ($i = 1; $i < count($sortby); $i++) {
  1961. $sortlist = $sortlist . " " . $sortby[$i];
  1962. }
  1963. }
  1964. for ($i = 0; $i < 4; $i++) {
  1965. $fieldmap[$i] = -1;
  1966. }
  1967. $multimode = 0;
  1968. for ($i = 0; $i < $numsearchfields; $i++) {
  1969. $searchstring[$i]["string"] = strtr($searchstring[$i]["string"],"`~!@#$%^&-_+={}[]|;:<>,.?/"," ");
  1970. if ($searchstring[$i]["field"] == "CISOSEARCHALL") {
  1971. $multimode = 1;
  1972. // $searchstring[$i]["string"] = strtolower($searchstring[$i]["string"]);
  1973. }
  1974. if (trim($searchstring[$i]["string"]) != "") {
  1975. if ($searchstring[$i]["mode"] == "all") {
  1976. $fieldmap[0] = $i;
  1977. }
  1978. elseif ($searchstring[$i]["mode"] == "exact") {
  1979. $fieldmap[1] = $i;
  1980. }
  1981. elseif ($searchstring[$i]["mode"] == "any") {
  1982. $fieldmap[2] = $i;
  1983. }
  1984. elseif ($searchstring[$i]["mode"] == "none") {
  1985. $fieldmap[3] = $i;
  1986. }
  1987. }
  1988. }
  1989. $searchlist = "";
  1990. if ($multimode == 1) { /* Search across all fields */
  1991. if ($fieldmap[1] >= 0) {
  1992. $searchlist = "(" . $searchstring[$fieldmap[1]]["string"] . ")";
  1993. }
  1994. if ($fieldmap[0] >= 0) {
  1995. if ($searchlist != "")
  1996. $searchlist = $searchlist . " and ";
  1997. $searchlist = $searchlist . "(" . AddOperator($searchstring[$fieldmap[0]]["string"],"and") . ")";
  1998. }
  1999. if ($fieldmap[2] >= 0) {
  2000. if ($searchlist != "")
  2001. $searchlist = $searchlist . " and ";
  2002. $searchlist = $searchlist . "(" . AddOperator($searchstring[$fieldmap[2]]["string"],"or") . ")";
  2003. }
  2004. if ($fieldmap[3] >= 0) {
  2005. if ($searchlist != "")
  2006. $searchlist = $searchlist . " not ";
  2007. else
  2008. $searchlist = "not ";
  2009. $searchlist = $searchlist . "(" . AddOperator($searchstring[$fieldmap[3]]["string"],"or") . ")";
  2010. }
  2011. }
  2012. else { /* Selected fields */
  2013. for ($i = 0; $i < $numsearchfields; $i++) {
  2014. if (trim($searchstring[$i]["string"]) != "") {
  2015. if ($searchstring[$i]["mode"] == "all") {
  2016. $searchlist = $searchlist . $searchstring[$i]["field"] . "=" . AddOperator($searchstring[$i]["string"],"and") . "\n";
  2017. }
  2018. elseif ($searchstring[$i]["mode"] == "exact") {
  2019. $searchlist = $searchlist . $searchstring[$i]["field"] . "=" . $searchstring[$i]["string"] . "\n";
  2020. }
  2021. elseif ($searchstring[$i]["mode"] == "any") {
  2022. $searchlist = $searchlist . $searchstring[$i]["field"] . "=" . AddOperator($searchstring[$i]["string"],"or") . "\n";
  2023. }
  2024. elseif ($searchstring[$i]["mode"] == "none") {
  2025. $searchlist = $searchlist . $searchstring[$i]["field"] . "=not " . AddOperator($searchstring[$i]["string"],"or") . "\n";
  2026. }
  2027. }
  2028. }
  2029. }
  2030. if (!extension_loaded('DmSearch')) {
  2031. if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
  2032. dl('php_dmsearchmod.dll');
  2033. }
  2034. else {
  2035. dl('dmsearch.so');
  2036. }
  2037. }
  2038. $dmid = dmGetUser();
  2039. if (isset($_SERVER["REMOTE_ADDR"]))
  2040. $remote_addr = $_SERVER["REMOTE_ADDR"];
  2041. else
  2042. $remote_addr = "";
  2043. if ($suppress == 1)
  2044. $multimode = $multimode + 20;
  2045. $result = dmsearch($dblist,$searchlist,$multimode,$docptr,$start,$maxrecs,$sortlist,$dmid,$remote_addr);
  2046. if (substr($result,0,1) == "0") {
  2047. $total = 0;
  2048. $n = 0;
  2049. $temp = strtok($result,"\n");
  2050. $p1 = strpos($temp," ");
  2051. if ($p1 != FALSE) {
  2052. $p2 = strpos($temp," ",$p1+1);
  2053. if ($p2 != FALSE) {
  2054. $total = (int) trim(substr($temp,$p2+1));
  2055. }
  2056. }
  2057. while (($temp = strtok("\n")) != FALSE) {
  2058. $p1 = strpos($temp," ");
  2059. $p2 = strpos($temp," ",$p1+1);
  2060. $record[$n]["collection"] = trim(substr($temp,0,$p1));
  2061. $record[$n]["pointer"] = trim(substr($temp,$p1+1,$p2-$p1-1));
  2062. $record[$n]["filetype"] = trim(substr($temp,$p2+1));
  2063. $record[$n]["parentobject"] = GetParent($record[$n]["collection"],$record[$n]["pointer"],$pathmap[$record[$n]["collection"]]);
  2064. $n++;
  2065. }
  2066. }
  2067. else { /* Error */
  2068. $total = 0;
  2069. }
  2070. }
  2071. /* Check if there are any metadata fields to return */
  2072. if (count($field) > 0) {
  2073. for ($i = 0; $i < count($record); $i++) {
  2074. dmGetItemInfo($record[$i]["collection"],$record[$i]["pointer"],$data);
  2075. if(!($parser = xml_parser_create()))
  2076. {
  2077. print("Error creating XML parser<br>");
  2078. exit();
  2079. }
  2080. xml_parse_into_struct($parser, $data, $structure, $index);
  2081. xml_parser_free($parser);
  2082. for ($j = 0; $j < count($field); $j++) {
  2083. $tag = strtoupper($field[$j]);
  2084. if (array_key_exists($tag,$index)) {
  2085. if (array_key_exists("value",$structure[$index[$tag][0]])) {
  2086. $record[$i][$field[$j]] = $structure[$index[$tag][0]]["value"];
  2087. }
  2088. else {
  2089. $record[$i][$field[$j]] = "";
  2090. }
  2091. }
  2092. else {
  2093. $record[$i][$field[$j]] = "";
  2094. }
  2095. }
  2096. }
  2097. }
  2098. return($record);
  2099. }
  2100. /* Get the parent compound object pointer, -1 if the item is not part of a compound object */
  2101. function GetParent($alias,$ptr,$path) {
  2102. $rc = CheckSuppFile($path,$ptr,"index.xml",$suppfn);
  2103. if (file_exists($suppfn)) { /* Check for compound object */
  2104. $xmlFile = fopen($suppfn,"r");
  2105. if (!($xmlFile)) {
  2106. return(-1);
  2107. }
  2108. $n = filesize($suppfn);
  2109. $xmlbuffer = fread($xmlFile,$n);
  2110. fclose($xmlFile);
  2111. $s = GetXMLField("parent",$xmlbuffer);
  2112. return($s);
  2113. }
  2114. else {
  2115. $rc = CheckSuppFile($path,$ptr,"newsindex.xml",$suppfn2);
  2116. if (file_exists($suppfn2)) { /* Check for newspaper */
  2117. $xmlFile = fopen($suppfn2,"r");
  2118. if (!($xmlFile)) {
  2119. return(-1);
  2120. }
  2121. $n = filesize($suppfn2);
  2122. $xmlbuffer = fread($xmlFile,$n);
  2123. fclose($xmlFile);
  2124. $s = GetXMLField("itemtype",$xmlbuffer);
  2125. if ($s == "Page") {
  2126. $issue = GetXMLField("issue",$xmlbuffer);
  2127. return($issue);
  2128. }
  2129. elseif ($s == "Article") {
  2130. $page = GetXMLField("page",$xmlbuffer);
  2131. $rc = CheckSuppFile($path,$page,"newsindex.xml",$suppfn3);
  2132. if (file_exists($suppfn3)) { /* Check for newspaper */
  2133. $xmlFile = fopen($suppfn3,"r");
  2134. if (!($xmlFile)) {
  2135. return(-1);
  2136. }
  2137. $n = filesize($suppfn3);
  2138. $xmlbuffer = fread($xmlFile,$n);
  2139. fclose($xmlFile);
  2140. $issue = GetXMLField("issue",$xmlbuffer);
  2141. return($issue);
  2142. }
  2143. }
  2144. else {
  2145. return(-1);
  2146. }
  2147. }
  2148. }
  2149. return(-1);
  2150. }
  2151. /* Check for existence of supp file */
  2152. function CheckSuppFile($loc,$ptr,$relfn,&$fn) {
  2153. $fn = $loc . "/supp/" . $ptr ."/" . $relfn;
  2154. if (!file_exists($fn)) {
  2155. if ($ptr >= 10000) {
  2156. $k = ((int)((int)$ptr / 10000)) * 10000;
  2157. $fn = $loc . "/supp/D" . $k . "/" . $ptr ."/" . $relfn;
  2158. if (!file_exists($fn))
  2159. $rc = -1; /* file does not exist */
  2160. else
  2161. $rc = 0; /* file exists */
  2162. }
  2163. else
  2164. $rc = -1; /* file does not exist */
  2165. }
  2166. else
  2167. $rc = 0; /* file exists */
  2168. return($rc);
  2169. }
  2170. /* Return the XML field */
  2171. function GetXMLField($tag,$xmlbuffer) {
  2172. $tagstart = "<" . $tag . ">";
  2173. $tagend = "</" . $tag . ">";
  2174. $p1 = strpos($xmlbuffer,$tagstart);
  2175. $p2 = strpos($xmlbuffer,$tagend);
  2176. if (($p1 === FALSE) || ($p2 === FALSE) || ($p2 < $p1)) {
  2177. $s = "";
  2178. return($s);
  2179. }
  2180. $l = strlen($tagstart);
  2181. if (($p1 + $l) == $p2) {
  2182. $s = "";
  2183. return($s);
  2184. }
  2185. $s = substr($xmlbuffer,$p1+$l,$p2-$p1-$l);
  2186. return($s);
  2187. }
  2188. function ReadFindURL() {
  2189. $fd = fopen(FINDCONF_FILE,"r");
  2190. if (!($fd)) {
  2191. print("Error opening conf/findconf.txt file<br>\n");
  2192. exit;
  2193. }
  2194. $findurl = "";
  2195. while (!feof($fd)) {
  2196. $s = fgets($fd,1024);
  2197. if (substr($s,0,7) == "FINDURL") {
  2198. $findurl = trim(substr($s,7));
  2199. break;
  2200. }
  2201. }
  2202. fclose($fd);
  2203. return($findurl);
  2204. }
  2205. /* Add the search operator to the search string */
  2206. function AddOperator($s,$op) {
  2207. $t = "";
  2208. $string = trim($s);
  2209. if ($string == "")
  2210. return($t);
  2211. $t = strtok($s," ");
  2212. if (strlen($t) >= WORDSIZE)
  2213. $t = substr($t,0,WORDSIZE);
  2214. $lt = strtolower($t);
  2215. if (($lt == "and") || ($lt == "or") || ($lt == "not"))
  2216. $t = "";
  2217. while (($word = strtok(" ")) != FALSE) {
  2218. $u = trim($word);
  2219. if (strlen($u) >= WORDSIZE)
  2220. $u = substr($u,0,WORDSIZE);
  2221. $lu = strtolower($u);
  2222. if (($u != "") && ($lu != "and") && ($lu != "or") && ($lu != "not")) {
  2223. $t = $t . " " . $op . " " . $u;
  2224. }
  2225. }
  2226. return($t);
  2227. }
  2228. /* Return file extension */
  2229. function GetFileEXt($filename) {
  2230. $p = strrpos($filename,".");
  2231. if ($p > 0) {
  2232. $ext = trim(strtolower(substr($filename,$p+1,strlen($filename)-$p-1)));
  2233. }
  2234. else {
  2235. $ext = "";
  2236. }
  2237. return($ext);
  2238. }
  2239. /* Return the print file link */
  2240. /* Returns: -1 = no print file, 0 = print file exists */
  2241. function dmGetPrintFileInfo($alias,$ptr,&$link) {
  2242. $rc = dmGetCollectionParameters($alias,$name,$path);
  2243. if ($rc < 0) {
  2244. if ($rc == -1) {
  2245. return(-1); /* no collection permission */
  2246. }
  2247. print("Error looking up collection $alias<br>\n");
  2248. exit;
  2249. }
  2250. $rc2 = CheckSuppFile($path,$ptr,"index.pdf",$printlink);
  2251. if ($rc2 == -1)
  2252. $rc2 = CheckSuppFile($path,$ptr,"index.html",$printlink);
  2253. if (file_exists($printlink)) {
  2254. $link = "/cgi-bin/showfile.exe?CISOROOT=" . $alias . "&CISOPTR=" . $ptr . "&CISOMODE=print";
  2255. $rc = 0;
  2256. }
  2257. else
  2258. $rc = -1;
  2259. return($rc);
  2260. }
  2261. /* Get the Server locale */
  2262. function dmGetLocale() {
  2263. $locale = "en_US"; /* default */
  2264. $localefile = CONF_DIR . "/locale.txt";
  2265. if (file_exists($localefile)) {
  2266. $fd = fopen($localefile,"r");
  2267. if ($fd) {
  2268. $s = fgets($fd,1024);
  2269. $locale = trim($s);
  2270. }
  2271. }
  2272. return($locale);
  2273. }
  2274. /* Format the date search string */
  2275. function FormatDateString($str) {
  2276. $result = "";
  2277. $s = str_replace("*","",$str);
  2278. $t = explode("-",$s);
  2279. if (count($t) == 1) {
  2280. /* single date case */
  2281. $l = strlen($s);
  2282. if ($l == 4)
  2283. $result = $s . "*";
  2284. elseif ($l == 6)
  2285. $result = substr($s,0,4) . "-" . substr($s,4,2) . "*";
  2286. elseif ($l == 8)
  2287. $result = substr($s,0,4) . "-" . substr($s,4,2) . "-" . substr($s,6,2);
  2288. else
  2289. $result = $str;
  2290. }
  2291. elseif (count($t) == 2) {
  2292. if ($t[0] == "00000000")
  2293. $t[0] = "1000";
  2294. $k = strlen($t[0]);
  2295. $l = strlen($t[1]);
  2296. if ($l == 2) {
  2297. $result = $s . "*";
  2298. }
  2299. elseif ((($k == 4) || ($k == 6) || ($k == 8)) && (($l == 4) || ($l == 6) || ($l == 8))) {
  2300. /* date range */
  2301. if ($k == 4) {
  2302. $startyear = (int) $t[0];
  2303. $smonth = 0;
  2304. $sday = 0;
  2305. }
  2306. elseif ($k == 6) {
  2307. $syear = (int) substr($t[0],0,4);
  2308. $result = $syear;
  2309. $startyear = $syear + 1;
  2310. $smonth = (int) $t[0];
  2311. $sday = 0;
  2312. }
  2313. elseif ($k == 8) {
  2314. $syear = (int) substr($t[0],0,4);
  2315. $startyear = $syear + 1;
  2316. $startmonth = (int) substr($t[0],0,6);
  2317. $smonth = $startmonth + 1;
  2318. $sday = (int) $t[0];
  2319. $result = $syear . " or " . substr($t[0],0,4) . "-" . substr($t[0],4,2);
  2320. }
  2321. if ($l == 4) {
  2322. $endyear = (int) $t[1];
  2323. $emonth = 999999;
  2324. $eday = 99999999;
  2325. }
  2326. elseif ($l == 6) {
  2327. $eyear = (int) substr($t[1],0,4);
  2328. $endyear = $eyear - 1;
  2329. $emonth = (int) $t[1];
  2330. $eday = 99999999;
  2331. }
  2332. elseif ($l == 8) {
  2333. $eyear = (int) substr($t[1],0,4);
  2334. $endyear = $eyear - 1;
  2335. $emonth = (int) substr($t[1],0,6);
  2336. $eday = (int) $t[1];
  2337. }
  2338. /* Handle a day count up to the month */
  2339. $end10 = (int) ($eday / 10);
  2340. if ($k == 8) {
  2341. if ($sday < $eday) {
  2342. $i = $sday;
  2343. while ($i < $eday) {
  2344. $j = $i % 100;
  2345. if ($j > 31)
  2346. break;
  2347. $m = $i % 10;
  2348. if (($j == 1) || ($m == 0)) {
  2349. $start10 = (int) ($i / 10);
  2350. if ($start10 < $end10) {
  2351. $u = (string) $i;
  2352. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,1) . "*";
  2353. $i = $i + 10;
  2354. if ($j == 1)
  2355. $i--;
  2356. }
  2357. else {
  2358. $u = (string) $i;
  2359. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,2);
  2360. $i++;
  2361. }
  2362. }
  2363. else {
  2364. $u = (string) $i;
  2365. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,2);
  2366. $i++;
  2367. }
  2368. }
  2369. }
  2370. }
  2371. /* Handle a month count up to the year */
  2372. if (($k == 6) || ($k == 8)) {
  2373. if ($smonth < $emonth) {
  2374. $i = $smonth;
  2375. while ($i < $emonth) {
  2376. $j = $i % 100;
  2377. if ($j > 12)
  2378. break;
  2379. $u = (string) $i;
  2380. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "*";
  2381. $i++;
  2382. }
  2383. }
  2384. }
  2385. /* Handle the intervening years */
  2386. if ($startyear <= $endyear) {
  2387. if (($startyear < 0) || ($endyear < 0))
  2388. return "";
  2389. $i = $startyear;
  2390. if ($result == "")
  2391. $op = "";
  2392. else
  2393. $op = " or ";
  2394. $enddecade = (int) ($endyear / 10);
  2395. $endcentury = (int) ($endyear / 100);
  2396. while ($i <= $endyear) {
  2397. if (($i % 100) == 0) {
  2398. $century = (int) ($i / 100);
  2399. if ($century < $endcentury) {
  2400. $result = $result . $op . $century . "*";
  2401. $i = $i + 100;
  2402. $op = " or ";
  2403. continue;
  2404. }
  2405. }
  2406. if (($i % 10) == 0) {
  2407. $decade = (int) ($i / 10);
  2408. if ($decade < $enddecade) {
  2409. $result = $result . $op . $decade . "*";
  2410. $i = $i + 10;
  2411. }
  2412. else {
  2413. $result = $result . $op . $i . "*";
  2414. $i++;
  2415. }
  2416. }
  2417. else {
  2418. $result = $result . $op . $i . "*";
  2419. $i++;
  2420. }
  2421. $op = " or ";
  2422. }
  2423. }
  2424. /* Handle a month count up to the end month */
  2425. if (($l == 6) || ($l == 8)) {
  2426. $i = ($eyear * 100) + 1;
  2427. while ($i < $emonth) {
  2428. $j = $i % 100;
  2429. if ($j > 12)
  2430. break;
  2431. if ($i > $smonth) {
  2432. $u = (string) $i;
  2433. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "*";
  2434. }
  2435. $i++;
  2436. }
  2437. $u = (string) $emonth;
  2438. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2);
  2439. if ($l == 6)
  2440. $result = $result . "*";
  2441. }
  2442. /* Handle a day count up to the day */
  2443. $end10 = (int) ($eday / 10);
  2444. if ($l == 8) {
  2445. if (($k == 8) && ($startmonth == $emonth)) {
  2446. $u = (string) $eday;
  2447. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,2);
  2448. }
  2449. else {
  2450. $i = ($emonth * 100) + 1;
  2451. while ($i <= $eday) {
  2452. $j = $i % 100;
  2453. if ($j > 31)
  2454. break;
  2455. if ($i > $smonth) {
  2456. $m = $i % 10;
  2457. if (($j == 1) || ($m == 0)) {
  2458. $start10 = (int) ($i / 10);
  2459. if ($start10 < $end10) {
  2460. $u = (string) $i;
  2461. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,1) . "*";
  2462. $i = $i + 10;
  2463. if ($j == 1)
  2464. $i--;
  2465. }
  2466. else {
  2467. $u = (string) $i;
  2468. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,2);
  2469. $i++;
  2470. }
  2471. }
  2472. else {
  2473. $u = (string) $i;
  2474. $result = $result . " or " . substr($u,0,4) . "-" . substr($u,4,2) . "-" . substr($u,6,2);
  2475. $i++;
  2476. }
  2477. }
  2478. else
  2479. $i++;
  2480. }
  2481. }
  2482. }
  2483. }
  2484. else
  2485. $result = "";
  2486. }
  2487. else {
  2488. /* single date case */
  2489. if (strlen($s) < 10)
  2490. $result = $s . "*";
  2491. else
  2492. $result = $s;
  2493. }
  2494. return $result;
  2495. }
  2496. function GetCatalogCount() {
  2497. /* Open the catalog.txt file */
  2498. $catalogFile = fopen(CATALOG_FILE,"r");
  2499. if (!($catalogFile)) {
  2500. print("Error opening catalog file");
  2501. exit;
  2502. }
  2503. $n = 0;
  2504. /* Read the collections from the catalog line by line */
  2505. while (!feof($catalogFile)) {
  2506. $s = fgets($catalogFile,512);
  2507. if (substr($s,0,1) == "/") {
  2508. $n++;
  2509. }
  2510. }
  2511. fclose($catalogFile);
  2512. return($n);
  2513. }
  2514. ?>