PageRenderTime 79ms CodeModel.GetById 26ms RepoModel.GetById 1ms 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

Large files files are truncated, but you can click here to view the full 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(su

Large files files are truncated, but you can click here to view the full file