PageRenderTime 71ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/apps/commodoro/functions.inc.php

https://github.com/noveopiu/dCTL
PHP | 2834 lines | 2616 code | 45 blank | 173 comment | 521 complexity | 819d7e203f56a1582c538bd794c7fdca MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!defined('_INCLUDE')) die('"'.__FILE__.'" not executable... me, i abort.');
  3. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4. function dctl_segmentize($theString) {
  5. $resultText = '::';
  6. $theArray = explode(DISTINCT_SEP2, $theString);
  7. $hash = array();
  8. foreach($theArray as $idx=>$theLine) {
  9. $thisLine = $theArray{$idx};
  10. if ($thisLine != '') {
  11. $theValues = explode(DISTINCT_SEP, $thisLine);
  12. $theCantoLabel = $theValues[0];
  13. $theCanto = intval(substr($theValues[1], 1));
  14. $theOctave = intval($theValues[2]);
  15. $theSegmentStart = intval($theValues[3]);
  16. $theSegmentEnd = intval($theValues[4]);
  17. $theOctaveCount = intval($theValues[5]);
  18. if ((($theSegmentStart == 1) && ($theSegmentEnd == $theOctaveCount)) || ($theOctaveCount == 0) || ($theSegmentStart == 0) || ($theSegmentEnd == 0)) {
  19. $theVerse = '';
  20. } else {
  21. if ($theSegmentStart != $theSegmentEnd) {
  22. $theVerse = ', vv.'.$theSegmentStart.'-'.$theSegmentEnd;
  23. } else {
  24. $theVerse = ', v.'.$theSegmentStart;
  25. };
  26. };
  27. $hash[$idx]['c'] = $theCanto;
  28. $hash[$idx]['l'] = $theCantoLabel;
  29. $hash[$idx]['o'] = $theOctave;
  30. $hash[$idx]['v'] = $theVerse;
  31. };
  32. };
  33. $idx = count($hash)-1;
  34. while (isset($hash[$idx-1])) {
  35. if ($hash[$idx]['c'] != $hash[$idx-1]['c'])
  36. $resultText = '; '.$hash[$idx]['l'].$resultText;
  37. --$idx;
  38. };
  39. return $resultText;
  40. };
  41. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  42. function SimpleXMLElementObj_into_xml($xml_parent, $xml_children, $linkingNode= "linkingNode" , $child_count = 0 , $simplexml = false ){
  43. if(!$simplexml) {
  44. $simplexml = $xml_parent->addChild($linkingNode);
  45. }else{
  46. $simplexml = $xml_parent[$child_count];
  47. }
  48. $child_count = 0;
  49. foreach($xml_children->children() as $k => $v) {
  50. if($simplexml->$k){
  51. $child_count++;
  52. }
  53. if($v->children()) {
  54. $simplexml->addChild($k);
  55. SimpleXMLElementObj_into_xml($simplexml->$k, $v, '', $child_count, true);
  56. }else{
  57. $simplexml->addChild($k, $v);
  58. }
  59. }
  60. return $simplexml;
  61. };
  62. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  63. function simplexml_append(SimpleXMLElement $parent, SimpleXMLElement $new_child){
  64. $node1 = dom_import_simplexml($parent);
  65. $dom_sxe = dom_import_simplexml($new_child);
  66. $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
  67. $node1->appendChild($node2);
  68. };
  69. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  70. function simplexml_insert(SimpleXMLElement $parent, SimpleXMLElement $new_child){
  71. $node1 = dom_import_simplexml($parent);
  72. $dom_sxe = dom_import_simplexml($new_child);
  73. $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
  74. $node1->parentNode->insertBefore($node2, $node1);
  75. };
  76. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  77. function generateId($random_id_length = 10) {
  78. //generate a random id encrypt it and store it in $rnd_id
  79. $rnd_id = crypt(uniqid(rand(),1));
  80. //to remove any slashes that might have come
  81. $rnd_id = strip_tags(stripslashes($rnd_id));
  82. //Removing any . or / and reversing the string
  83. $rnd_id = str_replace(".","",$rnd_id);
  84. $rnd_id = strrev(str_replace("/","",$rnd_id));
  85. //finally I take the first $random_id_length characters from the $rnd_id
  86. return substr($rnd_id,0,$random_id_length);
  87. };
  88. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  89. function getNiceId ($id, $niceId) {
  90. if (! preg_match('/^p\d{3}/', $id)) {
  91. $id = $niceId.'_'.$id;
  92. };
  93. return $id;
  94. };
  95. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  96. function ajax_deleteLink($id1='', $id2='', $label='', $what='', $overwrite=TRUE) {
  97. $resultText = '';
  98. $resultOK = '';
  99. $resultKO = '';
  100. $collection_id = '';
  101. switch ($what) {
  102. case 'lnk':
  103. $collection_id = explode('-', $id1);
  104. break;
  105. case 'map':
  106. $collection_id = explode('/',str_ireplace('xml://','',$id2));
  107. break;
  108. };
  109. $collection_id = $collection_id [0];
  110. if ($collection_id != '') {
  111. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  112. switch ($what) {
  113. case 'lnk':
  114. $thePath .= DCTL_FILE_LINKER;
  115. break;
  116. case 'map':
  117. $thePath .= DCTL_FILE_MAPPER;
  118. break;
  119. default:
  120. $resultKO .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  121. break;
  122. };
  123. if (is_file($thePath)) {
  124. $file_content = file_get_contents($thePath);
  125. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  126. $text_head = substr($file_content,0,stripos($file_content,'%BEGIN%')).'%BEGIN% -->';
  127. $text_foot = '<!-- '.substr($file_content,stripos($file_content,'%END%'));
  128. $dom = new DOMDocument('1.0', 'UTF-8');
  129. $dom->preserveWhiteSpace = false;
  130. forceUTF8($thePath);
  131. if ($dom->load($thePath, DCTL_XML_LOADER)) {
  132. $xpath = new DOMXPath($dom);
  133. switch ($id2) {
  134. case '': // elimina un collegamento intero
  135. $query = 'id("'.$id1.'")';
  136. $entries = $xpath->query($query);
  137. foreach ($entries as $entry) {
  138. $entry->parentNode->removeChild($entry);
  139. };
  140. break;
  141. default: // elimina un id
  142. $query = 'id("'.$id1.'")';
  143. $entries = $xpath->query($query);
  144. foreach ($entries as $entry) {
  145. $target = $entry->getAttribute('target');
  146. $target = str_ireplace($id2,'',$target);
  147. if (substr_count($target,'://')<2) { // elimina un collegamento intero
  148. $entry->parentNode->removeChild($entry);
  149. } else {
  150. $entry->setAttribute('target', $target);
  151. };
  152. };
  153. break;
  154. };
  155. if ($resultKO == '') {
  156. $file_content = $dom->saveXML();
  157. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  158. $from = stripos($file_content,'%BEGIN%')+strlen('%BEGIN% -->');
  159. $to = stripos($file_content,'%END%')-strlen('<-- ') - $from -1;
  160. $text_content = substr($file_content,$from,$to);
  161. $file_content = $text_head.$text_content.$text_foot;
  162. if ($overwrite) {
  163. doBackup($thePath);
  164. if (file_put_contents($thePath, forceUTF8($file_content), LOCK_EX) === false) {
  165. $resultKO .= 'Impossibile scrivere il file "'.basename($thePath).'"';
  166. } else {
  167. @chmod($thePath, CHMOD);
  168. $resultOK .= 'Modifica eseguita con successo ("'.$label.'")';
  169. };
  170. } else {
  171. $resultOK .= 'Simulazione eseguita con successo ("'.$label.'")';
  172. };
  173. };
  174. } else {
  175. $resultKO .= 'Impossibile leggere il file "'.basename($thePath).'"';
  176. };
  177. } else {
  178. $resultKO .= 'Impossibile trovare "'.basename($thePath).'"';
  179. };
  180. } else {
  181. $resultKO .= 'Impossibile trovare la collection...';
  182. };
  183. if ($resultKO !='') {
  184. $resultText .= '<span class="error">'.cleanWebString($resultKO).'</span>';
  185. } else {
  186. $resultText .= '<span class="ok">'.cleanWebString($resultOK).'</span>';
  187. };
  188. return $resultText;
  189. };
  190. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  191. function ajax_saveLink($selector = 'new', $id1='', $id2='', $label='', $what='', $overwrite=TRUE) {
  192. $resultText = '';
  193. $resultOK = '';
  194. $resultKO = '';
  195. $collection_id = explode('/',str_ireplace('xml://','',$id1));
  196. $collection_id = $collection_id [0];
  197. if ($collection_id != '') {
  198. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  199. switch ($what ) {
  200. case 'lnk':
  201. $thePath .= DCTL_FILE_LINKER;
  202. break;
  203. case 'map':
  204. $thePath .= DCTL_FILE_MAPPER;
  205. break;
  206. default:
  207. $resultKO .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  208. break;
  209. };
  210. if (is_file($thePath)) {
  211. switch ($selector) {
  212. case 'new':
  213. case 'add':
  214. case 'mod':
  215. case 'ovw':
  216. $file_content = file_get_contents($thePath);
  217. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  218. $text_head = substr($file_content,0,stripos($file_content,'%BEGIN%')).'%BEGIN% -->';
  219. $text_foot = '<!-- '.substr($file_content,stripos($file_content,'%END%'));
  220. $dom = new DOMDocument('1.0', 'UTF-8');
  221. $dom->preserveWhiteSpace = false;
  222. forceUTF8($thePath);
  223. if ($dom->load($thePath, DCTL_XML_LOADER)) {
  224. $xpath = new DOMXPath($dom);
  225. switch ($selector) {
  226. case 'new':
  227. $type = 'link';
  228. $thisID = $collection_id.'-'.generateId();
  229. $head = $label;
  230. $query = 'id("placeholder")';
  231. $entries = $xpath->query($query);
  232. foreach ($entries as $entry) {
  233. $newNode = $dom->createElement('ref', $head);
  234. $newNode = $entry->parentNode->insertBefore($newNode,$entry);
  235. $newNode->setAttribute('xml:id',$thisID);
  236. $newNode->setAttribute('type',$type);
  237. $newNode->setAttribute('n',$label);
  238. $newNode->setAttribute('target',$id1.' '.$id2);
  239. $newNode = $dom->createComment(' ');
  240. $newNode = $entry->parentNode->insertBefore($newNode,$entry);
  241. };
  242. break;
  243. case 'add':
  244. $query = 'id("'.$id2.'")';
  245. $entries = $xpath->query($query);
  246. foreach ($entries as $entry) {
  247. $target = $entry->getAttribute('target');
  248. if (stripos($target, $id1)=== FALSE) {
  249. $entry->setAttribute('target', $id1.' '.$target);
  250. } else {
  251. $resultKO .= 'L\'ID "'.$id1.'" è gia nel collegamento';
  252. };
  253. };
  254. break;
  255. case 'mod':
  256. $query = 'id("'.$id2.'")';
  257. $entries = $xpath->query($query);
  258. foreach ($entries as $entry) {
  259. $entry->setAttribute('n', $label);
  260. if ((string)$entry->nodeValue =='') $entry->nodeValue = $label;
  261. };
  262. break;
  263. case 'ovw':
  264. $query = 'id("'.$id2.'")';
  265. $entries = $xpath->query($query);
  266. foreach ($entries as $entry) {
  267. $entry->setAttribute('n', $label);
  268. $entry->setAttribute('target',$id1);
  269. if ((string)$entry->nodeValue == '') $entry->nodeValue = $label;
  270. };
  271. break;
  272. };
  273. if ($resultKO == '') {
  274. $file_content = $dom->saveXML();
  275. $file_content = preg_replace('/'.WS.'+/',' ',$file_content);
  276. $from = stripos($file_content,'%BEGIN%')+strlen('%BEGIN% -->');
  277. $to = stripos($file_content,'%END%')-strlen('<-- ') - $from -1;
  278. $text_content = substr($file_content,$from,$to);
  279. $file_content = $text_head.$text_content.$text_foot;
  280. if ($overwrite) {
  281. doBackup($thePath);
  282. if (file_put_contents($thePath, forceUTF8($file_content), LOCK_EX) === false) {
  283. $resultKO .= 'Impossibile scrivere il file "'.basename($thePath).'"';
  284. } else {
  285. @chmod($thePath, CHMOD);
  286. $resultOK .= 'Modifica eseguita con successo ("'.$label.'")';
  287. };
  288. } else {
  289. $resultOK .= 'Simulazione eseguita con successo ("'.$label.'")';
  290. };
  291. };
  292. } else {
  293. $resultKO .= 'Impossibile leggere il file "'.basename($thePath).'"';
  294. };
  295. break;
  296. default:
  297. $resultKO .= '?'.$selector.'?';
  298. break;
  299. };
  300. } else {
  301. $resultKO .= 'Impossibile trovare "'.basename($thePath).'"';
  302. };
  303. } else {
  304. $resultKO .= 'Impossibile trovare la collection...';
  305. };
  306. if ($resultKO !='') {
  307. $resultText .= '<span class="error">'.cleanWebString($resultKO).'</span>';
  308. } else {
  309. $resultText .= '<span class="ok">'.cleanWebString($resultOK).'</span>';
  310. };
  311. return $resultText;
  312. };
  313. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  314. function ajax_loadImageMap ($selector = 1, $id='', $uri='', $img='', $dim=array(), $coord=array(), $what='') {
  315. $resultText = '';
  316. if (is_array($coord)) {
  317. $resultText .= '$(\':input[name=xml_id2]\').addClass(\'active\').val(\''.$uri.'@'.implode(',', $coord).'\');';
  318. } else{
  319. $coord = array('0','0','0','0');
  320. $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
  321. };
  322. $resultText .= '$(\'img#img_edit\')';
  323. if ($id == '') {
  324. $resultText .= '.imgAreaSelect({disable:true, hide:true})';
  325. } else {
  326. $resultText .= '.attr(\'dbg\',\'1\')';
  327. $resultText .= '.unbind(\'load\')';
  328. $resultText .= '.load(function() {';
  329. $resultText .= 'if ($(\'img#img_edit\').attr(\'dbg\')) {';
  330. $resultText .= '$(\'img#img_edit\').removeAttr(\'dbg\');';
  331. $resultText .= 'var hRatio = $(\'img#img_edit\').width()/'.$dim[0].';';
  332. $resultText .= 'var vRatio = $(\'img#img_edit\').height()/'.$dim[1].';';
  333. $resultText .= '$(\'img#img_edit\').imgAreaSelect({enable:true, hide:true, x1:0, y1:0, x2:0, y2:0, outerOpacity: 0.17, imageWidth:'.$dim[0].', imageHeight:'.$dim[1].'});';
  334. $resultText .= '$(\'img#img_edit\').imgAreaSelect({x1:'.$coord[0].'*hRatio, y1:'.$coord[1].'*vRatio, x2:'.$coord[2].'*hRatio, y2:'.$coord[3].'*vRatio, onSelectEnd: function (img, selection) {
  335. $(\':input[name=xml_id2]\').val(\''.$uri.'@\'+selection.x1+\',\'+selection.y1+\',\'+selection.x2+\',\'+selection.y2).addClass(\'active\');
  336. }
  337. });';
  338. $resultText .= '};';
  339. $resultText .= '})';
  340. };
  341. $resultText .= '.attr(\'src\', \''.$img.'\')';
  342. return $resultText;
  343. };
  344. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  345. function ajax_loadImageList ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  346. $resultText = '';
  347. switch ($what ) {
  348. case 'lnk':
  349. break;
  350. case 'map':
  351. $resultText .= '<script>';
  352. $resultText .= '$(\'img#img_edit\').attr(\'src\', \'\').imgAreaSelect({disable:true, hide:true});';
  353. $resultText .= '</script>';
  354. break;
  355. default:
  356. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  357. break;
  358. };
  359. $resultText .= '<ul class="simpleTree">';
  360. $resultText .= '<li class="root">';
  361. $basePath = DCTL_PROJECT_PATH;
  362. $basePath .= $collection_id.SYS_PATH_SEP;
  363. getCollectionRecord($basePath, &$collectionRecord);
  364. $resultText .= '<span class="text">'.$collectionRecord['collection_full'].'</span>';
  365. $resultText .= '<ul>';
  366. $resultText .= '<li class="line"/>';
  367. $resultText .= '<li class="folder-open-last">';
  368. $basePath .= $package_id.SYS_PATH_SEP;
  369. getPackageRecord($basePath, &$packageRecord);
  370. $resultText .= '<span class="text">'.$packageRecord['package_full'].'</span>';
  371. $basePath .= SYS_PATH_SEP.$part_id;
  372. getPartRecord($basePath, &$partRecord);
  373. $resultText .= '<ul>';
  374. $resultText .= '<li class="line"/>';
  375. $resultText .= '<li class="folder-open-last">';
  376. $resultText .= '<span class="text">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH).'</span>';
  377. $resultText .= '<ul>';
  378. $basePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id;
  379. if(getImageList($basePath, &$imageList)>0) {
  380. foreach ($imageList['path'] as $key=>$fPath) {
  381. getImageRecord($fPath, &$imageRecord, $imageList['image_short'][$key]);
  382. $resultText .= '<li class="line"/>';
  383. $resultText .= '<li class="doc'.(($key+1)==count($imageList['path'])?'-last':'').'">';
  384. // carica IMG
  385. $img = ajax_loadImage($collection_id.SYS_PATH_SEP.DCTL_MEDIA_BIG.$imageRecord['image_id'], $dim, $what);
  386. if ($img) {
  387. $mapped = ajax_loadLinkList($selector, $collection_id, $package_id, $part_id, $item_id, $what);
  388. $mapped = preg_match('/(.*)\?(.*)\#(.*)\@(.*)/', $mapped, $matches);
  389. if ($mapped) {
  390. $uri = $matches[3];
  391. } else {
  392. $uri = 'img://'.$imageRecord['image_id'];
  393. };
  394. $coord = '';
  395. $mapped = $mapped && ($item_id != '');
  396. if ($mapped) {
  397. $mapped = (basename($img) == basename($uri));
  398. $coord = explode(',', $matches[4]);
  399. };
  400. if ($mapped) {
  401. $resultText .= '<span class="active">';
  402. $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
  403. } else {
  404. $resultText .= '<span class="text">';
  405. $resultText .= '<a href="javascript:void(0);" onclick="';
  406. $resultText .= '$(this).parents(\'ul\').find(\'.active\').removeClass(\'active\');';
  407. $resultText .= '$(this).parent().addClass(\'active\');';
  408. $resultText .= ajax_loadImageMap($selector, $item_id, $uri, $img, $dim, $coord, $what);
  409. $resultText .= ';" title="#">';
  410. $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
  411. $resultText .= '</a>';
  412. };
  413. } else {
  414. $resultText .= '<em>Not found: ';
  415. $resultText .= cleanWebString($imageRecord['image_work'].': '.$imageRecord['image_short'], FIELD_STRING_LENGTH);
  416. $resultText .= '</em>';
  417. };
  418. $resultText .= '</span>';
  419. $resultText .= '</li>';
  420. };
  421. $resultText .= '<script>';
  422. $resultText .= '$(\'#xml_tree2 .simpleTree\').find(\'.active\').parents(\'ul\').find(\'li span a\').each(function() {
  423. $(this).parent().replaceWith($(this).text());
  424. });';
  425. $resultText .= '</script>';
  426. } else {
  427. $resultText .= '<li class="doc-last"><i>nessuna figure</i></li>';
  428. };
  429. $resultText .= '</ul>';
  430. $resultText .= '</li>';
  431. $resultText .= '</ul>';
  432. $resultText .= '</li>';
  433. $resultText .= '</ul>';
  434. $resultText .= '</li>';
  435. $resultText .= '</ul>';
  436. return $resultText;
  437. };
  438. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  439. function ajax_loadLinkList ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what = '') {
  440. $fullItem = 'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$item_id;
  441. $resultText = '';
  442. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  443. switch ($what) {
  444. case 'lnk':
  445. $thePath .= DCTL_FILE_LINKER;
  446. break;
  447. case 'map':
  448. $thePath .= DCTL_FILE_MAPPER;
  449. break;
  450. default:
  451. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  452. break;
  453. };
  454. if (is_file($thePath)) {
  455. forceUTF8($thePath);
  456. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  457. $namespaces = $simplexml->getDocNamespaces();
  458. foreach ($namespaces as $nsk=>$ns) {
  459. if ($nsk == '') $nsk = 'tei';
  460. $simplexml->registerXPathNamespace($nsk, $ns);
  461. };
  462. $simplexml = simplexml_load_string(str_ireplace('xml:id','id',$simplexml->asXML()), 'SimpleXMLElement');
  463. // $s1=' '.$fullItem.' ';
  464. // $s2=$fullItem.' ';
  465. // $s3=' '.$fullItem;
  466. // $resultXML = $simplexml->xpath('//*[contains(@target,\''.$s1.'\') or contains(@target,\''.$s2.'\') or @target=\''.$fullItem.'\']');
  467. $fullItem = preg_replace('/(\.\d\d\d)/','.001',$fullItem);
  468. $resultXML = $simplexml->xpath('//*[contains(@target,\''.$fullItem.'\') and substring(substring-after(@target,\''.$fullItem.'\'),1,1) != "."]');
  469. if (count($resultXML)>0) {
  470. switch ($what) {
  471. case 'lnk': {
  472. $resultText .= '<ul class="simpleTree">';
  473. $resultText .= '<li class="root">Collegamenti';
  474. $resultText .= '<ul>';
  475. foreach($resultXML as $n=>$link) {
  476. $attrs = $link->attributes();
  477. $label = $attrs['n'];
  478. $resultText .= '<li>';
  479. $resultText .= '<span class="text" onclick="';
  480. // carica ID
  481. $resultText .= '$(\':input[name=xml_lnk'.$selector.']\').addClass(\'active\').attr({value:\''.$label.'\'});';
  482. $resultText .= '$(\':input[name=xml_lnk'.$selector.'id]\').addClass(\'active\').attr({value:\''.$attrs['id'].'\'});';
  483. $resultText .= '">';
  484. $resultText .= cleanWebString(stripslashes($attrs['n']), 40).'&#160;</span>';
  485. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'edit.gif" alt="edit" onclick="editLink(this, \''.$fullItem.'\',\''.$attrs['id'].'\', \''.$label.'\', \''.$what.'\')" />';
  486. if ($selector==2) {
  487. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'published_no.png" alt="delete" onclick="deleteLink(\''.$attrs['id'].'\',\'\',\''.$label.'\', \''.$what.'\')" />';
  488. };
  489. $resultText .= '<ul>';
  490. foreach(explode(' ',$link['target']) as $k=>$v) {
  491. if ($v!=''){
  492. $parsed = explode(SYS_PATH_SEP,$v);
  493. $lnk_coll =$parsed[2];
  494. switch (count($parsed)) {
  495. case 4: // xml://_coll_/_id_ => linker
  496. $lnk_pack = '';
  497. $lnk_part = '';
  498. $lnk_item = $parsed[3];
  499. break;
  500. case 5: // xml://_coll_/_pack_/_id_ => package
  501. $lnk_pack = $parsed[3];
  502. $lnk_part = array();
  503. if(preg_match('/\d\d\d/',$parsed[4],$lnk_part)) {
  504. $lnk_part = str_ireplace('$',$lnk_part[0],DCTL_PACKAGE_BODY);
  505. };
  506. $lnk_item = $parsed[4];
  507. break;
  508. };
  509. $resultText .= '<li>';
  510. $resultText .= '<span class="text">';
  511. $resultText .= '<a href="javascript:void(0);" onclick="';
  512. // carica XML
  513. $resultText .= '$(\'#xml_chunk\').load(\'indexAjax.php\', {action:\'ajax_loadChunk\', collection_id:\''.$lnk_coll.'\', package_id:\''.$lnk_pack.'\', part_id:\''.$lnk_part.'\', item_id:\''.$lnk_item.'\', what:\''.$what.'\'});';
  514. $resultText .= '" title="#">'.cleanWebString(str_ireplace('xml://'.$lnk_coll.SYS_PATH_SEP,'',$v)).'</a>';
  515. $resultText .= '</span>';
  516. if ($v == $fullItem) {
  517. if ($selector==1) {
  518. $fullItem2 = 'xml://'.$lnk_coll.SYS_PATH_SEP.$lnk_pack.SYS_PATH_SEP.$lnk_item;
  519. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'published_no.png" alt="" onclick="deleteLink(\''.$attrs['id'].'\',\''.$fullItem2.'\',\''.$label.'\', \''.$what.'\')" />';
  520. };
  521. };
  522. $resultText .= '</li>';
  523. };
  524. };
  525. $resultText .= '</ul>';
  526. $resultText .= '</li>';
  527. };
  528. $resultText .= '</ul>';
  529. $resultText .= '</li>';
  530. $resultText .= '</ul>';
  531. };
  532. break;
  533. case 'map': {
  534. foreach($resultXML as $n=>$link) {
  535. $attrs = $link->attributes();
  536. foreach(explode(' ',$link['target']) as $k=>$v) {
  537. if ($v != '') {
  538. if ($v != $fullItem) {
  539. $resultText = $attrs['id'].'?'.$attrs['n'].'#'.$v; // id ? label # uri @ map
  540. };
  541. };
  542. };
  543. };
  544. };
  545. break;
  546. default:
  547. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  548. break;
  549. };
  550. };
  551. };
  552. return $resultText;
  553. };
  554. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  555. function ajax_loadId ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  556. $resultText = '';
  557. $resultText .= '<a href="javascript:void(0);" onclick="';
  558. $resultText .= '$(\'#xml_chunk\').load(\'indexAjax.php\', {action:\'ajax_loadChunk\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$item_id.'\', what:\''.$what.'\'});';
  559. $resultText .= '" title="#">';
  560. $fullItem = 'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$item_id;
  561. $resultText .= cleanWebString($fullItem);
  562. $resultText .= '</a>';
  563. return $resultText;
  564. };
  565. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  566. function ajax_loadChunk ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  567. $resultText = '';
  568. $fullItem = $collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id;
  569. $thePath = DCTL_PROJECT_PATH.$fullItem;
  570. // $resultText .= '<div class="lineH2">'.htmlentities($collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$part_id.SYS_PATH_SEP.$item_id,ENT_QUOTES,'UTF-8').'</div>';
  571. if (is_file($thePath)) {
  572. forceUTF8($thePath);
  573. $simplexml = simplexml_load_file($thePath, 'asPrettyXMLElement', DCTL_XML_LOADER);
  574. $namespaces = $simplexml->getDocNamespaces();
  575. foreach ($namespaces as $nsk=>$ns) {
  576. if ($nsk == '') $nsk = 'tei';
  577. $simplexml->registerXPathNamespace($nsk, $ns);
  578. };
  579. $resultXML = $simplexml->xpath('id("'.$item_id.'")');
  580. if (count($resultXML)>0) {
  581. $high = 'xml:id=&quot;'.$item_id.'&quot;';
  582. $xxml = htmlentities($resultXML[0]->asPrettyXML(1),ENT_QUOTES,'UTF-8');
  583. $resultText .= '<pre>'.str_ireplace($high,'<span class="highlight">'.$high.'</span>', $xxml).'</pre>';
  584. } else {
  585. $resultText .= '<span class="error">Non trovo ID '.$item_id.'...</span>';
  586. };
  587. } else {
  588. $resultText .= '<span class="error">Non trovo '.$fullItem.'...</span>';
  589. };
  590. return $resultText;
  591. };
  592. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  593. function ajax_loadImage ($fullItem='', &$dim=array(), $what='') {
  594. $resultText = '';
  595. $thePath = DCTL_PROJECT_PATH.$fullItem;
  596. if (is_file($thePath)) {
  597. $dim = getimagesize($thePath);
  598. $thePath = str_ireplace(DCTL_PROJECT_PATH, HOST_BASE_PATH.'data'.WEB_PATH_SEP.'dctl-project'.WEB_PATH_SEP, $thePath);
  599. $resultText .= $thePath;
  600. } else {
  601. $resultText .= '';
  602. };
  603. return $resultText;
  604. };
  605. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  606. function ajax_loadTree ($selector = 1, $collection_id='', $package_id='', $part_id='', $item_id='', $what='') {
  607. $resultText = '';
  608. if (DCTL_EXT_IMT) {
  609. } else {
  610. switch ($what ) {
  611. case 'lnk':
  612. break;
  613. case 'map':
  614. $resultText .= '<script>';
  615. $resultText .= '$(\'img#img_edit\').attr(\'src\', \'\').imgAreaSelect({disable:true, hide:true});';
  616. $resultText .= '$(\':input[name=xml_id1]\').removeClass(\'active\').val(\'\');';
  617. $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
  618. $resultText .= '$(\':input[name=xml_label]\').removeClass(\'active\').val(\'\');';
  619. $resultText .= '$(\':input[name=xml_lnk1id]\').removeClass(\'active\').val(\'\');';
  620. $resultText .= '$(\'#xml_tree2\').html(\'\');';
  621. $resultText .= '</script>';
  622. break;
  623. default:
  624. $resultText .= 'ERROR: CASE UNIMPLEMENTED IN '.__FUNCTION__;
  625. break;
  626. };
  627. };
  628. // BEGIN
  629. $basePath = DCTL_PROJECT_PATH;
  630. $collectionPath = $basePath.$collection_id.SYS_PATH_SEP;
  631. if ($collection_id == '') {
  632. /*
  633. // ALL COLLECTIONS
  634. $resultText .= '<ul>';
  635. getCollectionList($basePath, &$collectionList);
  636. foreach ($collectionList['path'] as $key=>$fPath) {
  637. getCollectionRecord($fPath, &$collectionRecord);
  638. $resultText .= '<li>';
  639. $resultText .= '<span class="text">'.cleanWebString($collectionRecord['collection_short'].' - '.$collectionRecord['collection_work'], FIELD_STRING_LENGTH).'</span>';
  640. $resultText .= '<ul class="ajax">';
  641. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&amp;selector='.$selector.'&amp;collection_id='.$collectionRecord['collection_id'].'}</li>';
  642. $resultText .= '</ul>';
  643. $resultText .= '</li>';
  644. };
  645. $resultText .= '</ul>';
  646. */
  647. } else {
  648. if ($package_id=='') {
  649. $resultText .= '<ul class="simpleTree">';
  650. getCollectionRecord($collectionPath, &$collectionRecord);
  651. $resultText .= '<li class="root">';
  652. $resultText .= '<span class="text">'.$collectionRecord['collection_full'].'</span>';
  653. };
  654. $basePath = $collectionPath;
  655. $packagePath = $basePath.$package_id.SYS_PATH_SEP;
  656. // ONE COLLECTION
  657. if ($package_id == '') {
  658. // ALL PACKAGES
  659. $resultText .= '<ul>';
  660. getPackageList($basePath, &$packageList);
  661. foreach ($packageList['path'] as $key=>$fPath) {
  662. getPackageRecord($fPath, &$packageRecord);
  663. $resultText .= '<li>';
  664. $resultText .= '<span class="text">'.$packageRecord['package_full'].'</span>';
  665. $resultText .= '<ul class="ajax">';
  666. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&amp;selector='.$selector.'&amp;collection_id='.$collection_id.'&amp;package_id='.$packageRecord['package_id'].'&amp;what='.$what.'}</li>';
  667. $resultText .= '</ul>';
  668. $resultText .= '</li>';
  669. };
  670. $resultText .= '</ul>';
  671. } else {
  672. // ONE PACKAGE
  673. $basePath = $packagePath;
  674. $partPath = $basePath.$part_id.SYS_PATH_SEP;
  675. if ($part_id == '') {
  676. // ALL PARTS
  677. $resultText .= '<ul>';
  678. getPartList($basePath, &$partList);
  679. foreach ($partList['path'] as $key=>$fPath) {
  680. getPartRecord($fPath, &$partRecord);
  681. $resultText .= '<li>';
  682. if (DCTL_EXT_IMT && $what=='map') {
  683. $resultText .= '<span class="text"><a href="javascript:void(0);" onclick="';
  684. $resultText .= 'doProgress();$.post(\'indexAjax.php\',{action:\'ajax_loadTree\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$partRecord['part_id'].'\', what:\''.$what.'\'},';
  685. $resultText .= ' function('.DCTL_EXT_IMT_CBP.'){ commdodoro_initializeIMT('.DCTL_EXT_IMT_CBP.'); killProgress();});';
  686. $resultText .= '">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH). '&#160;</a></span>';
  687. } else {
  688. $resultText .= '<span class="text" onclick="doProgress();$(this).next().load(\'indexAjax.php\',{action:\'ajax_loadTree\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$partRecord['part_id'].'\', what:\''.$what.'\'},function(){
  689. $(\'#xml_tree'.$selector.' .simpleTree\').get(0).setTreeNodes(this, false);
  690. killProgress();
  691. }).insertAfter(this);">'.cleanWebString($partRecord['part_short'].': '.$partRecord['part_work'], FIELD_STRING_LENGTH). '&#160;</span>';
  692. $resultText .= '<img src="'.DCTL_IMAGES.'refresh.gif" class="refresh" alt="(refresh)" onclick="doProgress();$(this).next().load(\'indexAjax.php\',{action:\'ajax_loadTree\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$partRecord['part_id'].'\', what:\''.$what.'\'},function(){
  693. $(\'#xml_tree'.$selector.' .simpleTree\').get(0).setTreeNodes(this, false);
  694. killProgress();
  695. }).insertAfter(this);" />';
  696. $resultText .= '<ul class="ajax">';
  697. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadTree&amp;selector='.$selector.'&amp;collection_id='.$collection_id.'&amp;package_id='.$package_id.'&amp;part_id='.$partRecord['part_id'].'&amp;what='.$what.'}</li>';
  698. $resultText .= '</ul>';
  699. };
  700. $resultText .= '</li>';
  701. };
  702. $resultText .= '</ul>';
  703. } else {
  704. $basePath = $partPath;
  705. $itemPath = $basePath.$item_id.SYS_PATH_SEP;
  706. // ONE PART
  707. if ($item_id == '') {
  708. // ALL ITEMS
  709. if (DCTL_EXT_IMT && $what=='map') {
  710. $resultText .= '<?xml version="1.0" encoding="UTF-8"?>';
  711. $resultText .= '<dctl_ext_init>';
  712. $resultText .= '<xml>';
  713. if(getItemList($basePath, &$itemList, $what)>0) {
  714. $thePath = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP.DCTL_FILE_MAPPER;
  715. if (is_file($thePath)) {
  716. forceUTF8($thePath);
  717. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  718. $namespaces = $simplexml->getDocNamespaces();
  719. foreach ($namespaces as $nsk=>$ns) {
  720. if ($nsk == '') $nsk = 'tei';
  721. $simplexml->registerXPathNamespace($nsk, $ns);
  722. };
  723. $simplexml = simplexml_load_string(str_ireplace('xml:id','id',$simplexml->asXML()), 'SimpleXMLElement');
  724. foreach ($itemList['path'] as $key=>$fPath) {
  725. $uri = 'xml://'.$collection_id.'/'.$package_id.'/'.$itemList['item_id'][$key];
  726. $content = $itemList['item_short'][$key];
  727. $ref = '';
  728. $target = '';
  729. $label = '';
  730. $fullItem = $uri;
  731. $fullItem = preg_replace('/(\.\d\d\d)/','.001',$fullItem);
  732. $resultXML = $simplexml->xpath('//*[contains(@target,\''.$fullItem.'\') and substring(substring-after(@target,\''.$fullItem.'\'),1,1) != "."]');
  733. if (count($resultXML)>0) {
  734. foreach($resultXML as $n=>$link) {
  735. $attrs = $link->attributes();
  736. foreach(explode(' ',$link['target']) as $k=>$v) {
  737. if ($v != '') {
  738. if ($v != $fullItem) {
  739. $ref = $attrs['id'];
  740. $target = $v;
  741. $label = $attrs['n'];
  742. };
  743. };
  744. };
  745. };
  746. };
  747. $resultText .= '<a';
  748. $resultText .= ' r="'.$ref.'"';
  749. $resultText .= ' s="'.$uri.'"';
  750. $resultText .= ' t="'.$target.'"';
  751. $resultText .= ' l="'.$label.'"';
  752. $resultText .= ' c="'.$content.'"';
  753. $resultText .= ' />';
  754. };
  755. } else {
  756. dump('ERRORE');
  757. };
  758. };
  759. $resultText .= '</xml>';
  760. $resultText .= '<img>';
  761. if(getImageList($basePath, &$imageList)>0) {
  762. $key = 0;
  763. if (isset($imageList['path'][$key])) {
  764. $uri = 'img://'.$imageList['image_id'][$key];
  765. $url = DCTL_EXT_URL.'/indexAjax.php?&amp;action=get_file&amp;collection_id='.$collection_id.'&amp;url='.DCTL_MEDIA_MED.$imageList['image_id'][$key];
  766. $label = $imageList['image_short'][$key];
  767. $resultText .= '<a';
  768. $resultText .= ' s="'.$uri.'"';
  769. $resultText .= ' u="'.$url.'"';
  770. $resultText .= ' l="'.$label.'"';
  771. $resultText .= ' />';
  772. };
  773. };
  774. $resultText .= '</img>';
  775. $resultText .= '<cb';
  776. $resultText .= ' u="'.DCTL_EXT_IMT_CB.'"';
  777. $resultText .= ' p="'.DCTL_EXT_IMT_CBP.'"';
  778. $resultText .= ' />';
  779. $resultText .= '</dctl_ext_init>';
  780. $resultText = base64_encode($resultText); //base64_encode
  781. } else {
  782. $resultText .= '<script>';
  783. switch ($what) {
  784. case 'lnk':
  785. break;
  786. case 'map':
  787. $resultText .= '$(\'#xml_tree'.($selector+1).'\').load(\'indexAjax.php\', {action:\'ajax_loadImageList\', selector:\''.($selector+1).'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', what:\''.$what.'\'});';
  788. break;
  789. default:
  790. $resultText .= 'alert(\'ERROR: CASE UNIMPLEMENTED IN ...'.__FUNCTION__.'\');';
  791. break;
  792. };
  793. $resultText .= '</script>';
  794. if(getItemList($basePath, &$itemList, $what)>0) {
  795. $resultText .= '<ul>';
  796. foreach ($itemList['path'] as $key=>$fPath) {
  797. getItemRecord($fPath, &$itemRecord, $itemList['item_short'][$key]);
  798. $resultText .= '<li>';
  799. $resultText .= '<span class="text">';
  800. if ($itemRecord['item_id'] != '') {
  801. $resultText .= '<a href="javascript:void(0);" onclick="';
  802. // carica XML
  803. $resultText .= '$(\'#xml_chunk\').load(\'indexAjax.php\', {action:\'ajax_loadChunk\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$itemRecord['item_short'].'\', what:\''.$what.'\'});';
  804. // carica ID
  805. $resultText .= '$(\':input[name=xml_id'.$selector.']\').addClass(\'active\').attr({value:\''.'xml://'.$collection_id.SYS_PATH_SEP.$package_id.SYS_PATH_SEP.$itemRecord['item_short'].'\'});';
  806. switch ($what) {
  807. case 'lnk':
  808. // carica LINK
  809. $resultText .= '$(\'#xml_lnk'.$selector.'\').load(\'indexAjax.php\', {action:\'ajax_loadLinkList\', selector:\''.$selector.'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$itemRecord['item_short'].'\', what:\''.$what.'\'}, function(){$(\'#xml_lnk'.$selector.' .simpleTree\').simpleTree({activeLeaf: false}); });';
  810. $resultText .= '" title="#">';
  811. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  812. break;
  813. case 'map':
  814. $mapped = ajax_loadLinkList($selector, $collection_id, $package_id, $part_id, $itemRecord['item_id'], $what);
  815. $mapped = preg_match('/(.*)\?(.*)\#(.*)\@(.*)/', $mapped, $matches);
  816. if ($mapped) {
  817. $ref = $matches[1];
  818. $label = $matches[2];
  819. } else {
  820. $ref = '';
  821. $label = $itemRecord['item_work'];
  822. };
  823. $resultText .= '$(\':input[name=xml_label]\').removeClass(\'active\').val(\''.str_ireplace('&apos;', "\\'", $label).'\');';
  824. $resultText .= '$(\':input[name=xml_id2]\').removeClass(\'active\').val(\'\');';
  825. $resultText .= '$(\':input[name=xml_lnk1id]\').addClass(\'active\').attr({value:\''.$ref.'\'});';
  826. $resultText .= '$(\'#xml_tree'.($selector+1).'\').load(\'indexAjax.php\', {action:\'ajax_loadImageList\', selector:\''.($selector+1).'\', collection_id:\''.$collection_id.'\', package_id:\''.$package_id.'\', part_id:\''.$part_id.'\', item_id:\''.$itemRecord['item_short'].'\', what:\''.$what.'\'}';
  827. if ($mapped) {
  828. $uri = $matches[3];
  829. $img = str_ireplace('img://', $collection_id.SYS_PATH_SEP.DCTL_MEDIA_BIG, $uri);
  830. $coord = explode(',', $matches[4]);
  831. $resultText .= ', function () {';
  832. $img = ajax_loadImage($img, $dim, $what);
  833. $resultText .= ajax_loadImageMap($selector, $itemRecord['item_id'], $uri, $img, $dim, $coord, $what);
  834. $resultText .= '}';
  835. };
  836. $resultText .= ');';
  837. $resultText .= '" title="#">';
  838. if ($mapped) {
  839. $resultText .= '<span class="dctl_ok">';
  840. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  841. $resultText .= '</span>';
  842. $resultText .= '&#160;&#160;<img src="'.DCTL_IMAGES.'published_no.png" alt="delete" onclick="deleteLink(\''.$matches[1].'\',\''.$matches[3].'@'.$matches[4].'\',\''.$matches[2].'\', \''.$what.'\')" />';
  843. } else {
  844. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  845. };
  846. break;
  847. default:
  848. $resultText .= 'alert(\'ERROR: CASE UNIMPLEMENTED IN ...'.__FUNCTION__.'\');';
  849. $resultText .= '" title="#">';
  850. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  851. break;
  852. };
  853. $resultText .= '</a>';
  854. } else {
  855. $resultText .= '<em class="dctl_ko">';
  856. $resultText .= cleanWebString($itemRecord['item_short'].': '.$itemRecord['item_work'], FIELD_STRING_LENGTH);
  857. $resultText .= '</em>';
  858. };
  859. $resultText .= '</span>';
  860. $resultText .= '</li>';
  861. };
  862. $resultText .= '</ul>';
  863. } else {
  864. $resultText .= '<li><i>nessun id</i></li>';
  865. };
  866. };
  867. } else {
  868. $resultText .= 'UNIMPLEMENTED';
  869. };
  870. };
  871. };
  872. if (DCTL_EXT_IMT && $what=='map') {
  873. // nothing
  874. } else {
  875. $resultText .= '</li>';
  876. $resultText .= '</ul>';
  877. };
  878. };
  879. return $resultText;
  880. };
  881. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  882. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  883. function isImage($mime,$ext) {
  884. if (
  885. ($mime=="image/gif")||
  886. ($mime=="image/jpeg")||
  887. ($mime=="image/jpg")||
  888. ($mime=="image/pjpeg")||
  889. ($mime=="image/png")||
  890. ($ext=="jpg")||
  891. ($ext=="jpeg")||
  892. ($ext=="png")||
  893. ($ext=="gif") ) {
  894. return true;
  895. } else {
  896. return false;
  897. };
  898. };
  899. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  900. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  901. function getMIME($file) {
  902. //If mime magic is installed
  903. if (function_exists("mime_content_type")) {
  904. $mime=mime_content_type($file);
  905. } else {
  906. $mime=image2MIME($file);
  907. if($mime==false) $mime="text/plain";
  908. }
  909. return strtolower($mime);
  910. };
  911. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  912. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  913. function image2MIME($file) {
  914. $fh=fopen($file,"r");
  915. if ($fh) {
  916. $start4=fread($fh,4);
  917. $start3=substr($start4,0,3);
  918. if ($start4=="\x89PNG") {
  919. return "image/png";
  920. } elseif ($start3=="GIF") {
  921. return "image/gif";
  922. } elseif ($start3=="\xFF\xD8\xFF") {
  923. return "image/jpeg";
  924. } elseif ($start4=="hsi1") {
  925. return "image/jpeg";
  926. } else {
  927. return false;
  928. }
  929. unset($start3);
  930. unset($start4);
  931. fclose($fh);
  932. } else {
  933. return false;
  934. }
  935. }
  936. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  937. function putEdit ($param = '') {
  938. $resultText = '';
  939. if (DCTL_USER_IS_EDITOR) {
  940. $resultText .= '<a onclick="javascript:doProgress();" class="edit" href="'.$_SERVER['PHP_SELF'].'?';
  941. foreach ($_REQUEST as $k=>$v) {
  942. if ($k == $param) $v = 'true';
  943. $resultText .= $k."=".$v."&amp;";
  944. };
  945. $param .= '=';
  946. if (stripos($param, $resultText) === false) $resultText .= $param.'true';
  947. $resultText .= '" title="modifica">';
  948. $resultText .= '&#160;<img src="'.DCTL_IMAGES.'application_form_edit.png" alt="(edit icon)" />';
  949. $resultText .= '&#160;Modifica dati</a>';
  950. };
  951. return $resultText;
  952. }
  953. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  954. function putOpenCloseLevel ($id, $loc4msg, $more=false, $label, &$resultMsg='') {
  955. $resultText = '';
  956. $isThis = ($loc4msg == $id) || $more;
  957. $resultText .= '<h3>';
  958. $resultText .= '<a class="toggler" onclick="toggleVisibility(this,\''.$id.'\');" title="'.TOOLTIP_TOGGLE.'">';
  959. $resultText .= '<img src="'.DCTL_IMAGES;
  960. if ($isThis) {
  961. $resultText .= 'collapse.gif';
  962. } else {
  963. $resultText .= 'expand.gif';
  964. };
  965. $resultText .= '" alt="(open/close level)" />&#160;';
  966. $resultText .= $label.'</a></h3>';
  967. $resultText .= '<div id="'.$id.'" class="';
  968. if ($isThis) {
  969. $resultText .= 'un';
  970. } else {
  971. $resultText .= '_hidden';
  972. };
  973. $resultText .= '">';
  974. if ($loc4msg == $id) {
  975. $resultText .= $resultMsg;
  976. }
  977. return $resultText;
  978. };
  979. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  980. function putOpenLevel ($id, $loc4msg, $more=false, $label, &$resultMsg='') {
  981. $resultText = '';
  982. $isThis = ($loc4msg == $id) || $more;
  983. $resultText .= '<h3>';
  984. $resultText .= '&#160;';
  985. $resultText .= $label.'</h3>';
  986. $resultText .= '<div id="'.$id.'" class="';
  987. $resultText .= '">';
  988. if ($loc4msg == $id) {
  989. $resultText .= $resultMsg;
  990. }
  991. return $resultText;
  992. };
  993. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  994. function getModel ($originalPath) {
  995. $sourcePath = $originalPath;
  996. $filePath = str_ireplace(DCTL_PROJECT_PATH, '', $sourcePath);
  997. $zip = new zipfile();
  998. $zipdir = SYS_PATH_SEP;
  999. $zip->add_dir($zipdir);
  1000. addToZip(DCTL_SETTINGS, $zip, $zipdir);
  1001. $zipdir = SYS_PATH_SEP;
  1002. $source = DCTL_PROJECT_PATH;
  1003. foreach(explode(SYS_PATH_SEP, $filePath) as $item) {
  1004. $source .= $item;
  1005. $zipdir .= $item;
  1006. if (is_dir($source)) {
  1007. $source .= SYS_PATH_SEP;
  1008. $zipdir .= SYS_PATH_SEP;
  1009. $zip->add_dir($zipdir);
  1010. $item = $source.DCTL_FILE_HEADER;
  1011. if (is_file($item)) {
  1012. addToZip($item, $zip, $zipdir);
  1013. };
  1014. // $item = $source.DCTL_MEDIA_SML;
  1015. // if (is_dir($item)) {
  1016. // addToZip($item, $zip, $zipdir);
  1017. // };
  1018. };
  1019. };
  1020. $zipdir = dirname($zipdir).SYS_PATH_SEP;
  1021. if (is_dir($source)) {
  1022. if ((stripos(DCTL_MEDIA_SML, $source) === FALSE) && (stripos(DCTL_MEDIA_MED, $source) === FALSE)) {
  1023. addToZip($source, $zip, $zipdir);
  1024. };
  1025. } else {
  1026. if (is_file($source)) {
  1027. $item = $source;
  1028. addToZip($item, $zip, $zipdir);
  1029. };
  1030. };
  1031. $filePath = dirname($originalPath).SYS_PATH_SEP.str_ireplace(SYS_PATH_SEP, '#', $filePath).'.zip';
  1032. $fd = fopen ($filePath, "wb");
  1033. $out = fwrite ($fd, $zip->file());
  1034. fclose ($fd);
  1035. @chmod($filePath, CHMOD);
  1036. return $filePath;
  1037. };
  1038. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1039. function getListNameForField ($theFields, $theSelected) {
  1040. global $COLLECTION_FIELDS;
  1041. global $PACKAGE_FIELDS;
  1042. $resultText = '';
  1043. switch ($theFields) {
  1044. case $COLLECTION_FIELDS:
  1045. switch ($theSelected) {
  1046. case 'collection_resp':
  1047. $resultText = DCTL_LIST_RESP;
  1048. break;
  1049. };
  1050. break;
  1051. case $PACKAGE_FIELDS:
  1052. switch ($theSelected) {
  1053. case 'package_encoder':
  1054. $resultText = DCTL_LIST_RESP;
  1055. break;
  1056. case 'source_lang':
  1057. $resultText = DCTL_LIST_LANG;
  1058. break;
  1059. case 'source_genre':
  1060. $resultText = DCTL_LIST_GENRE;
  1061. break;
  1062. case 'reference_lang':
  1063. $resultText = DCTL_LIST_LANG;
  1064. break;
  1065. case 'reference_genre':
  1066. $resultText = DCTL_LIST_GENRE;
  1067. break;
  1068. };
  1069. break;
  1070. };
  1071. return $resultText ;
  1072. };
  1073. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1074. function getTextClassList ($theList='', $theObject='') {
  1075. $resultText = '';
  1076. if ($theList != '') {
  1077. if ($theObject != '') {
  1078. $simplexml = '';
  1079. if (is_file(DCTL_SETTINGS_TEXTCLASS)) {
  1080. $resultText .= '<br />Aggiungi:<select onchange="javascript:addContent(\''.$theObject.'\', this.value);">';
  1081. $resultText .= '<option value="" selected="selected" />';
  1082. forceUTF8(DCTL_SETTINGS_TEXTCLASS);
  1083. $simplexml = simplexml_load_file(DCTL_SETTINGS_TEXTCLASS, 'SimpleXMLElement', DCTL_XML_LOADER);
  1084. $simplexml = $simplexml->asXML();
  1085. $simplexml = str_ireplace('xml:', '', $simplexml);
  1086. $simplexml = simplexml_load_string($simplexml, 'SimpleXMLElement', DCTL_XML_LOADER);
  1087. $resultXML = $simplexml->xpath('//classCode[@scheme="'.$theList.'"]/term');
  1088. foreach ($resultXML as $k=>$v) {
  1089. $id = strval($v['id']);
  1090. $name = strval($v->eg);
  1091. $resultText .= '<option value="'.$id.'">'.$name.SYS_DBL_SPACE.'</option>';
  1092. };
  1093. $resultText .= '</select>';
  1094. };
  1095. };
  1096. };
  1097. return $resultText ;
  1098. };
  1099. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1100. function getManagementOfImages ($fDivX, $labelX, $collection_id, $itemName, $loc4msg, &$fCount, $resultMsg) {
  1101. global $EXTENSION_ALLOWED;
  1102. global $EXTENSION_TEXT;
  1103. global $EXTENSION_GRAPHIC;
  1104. $resultText = '';
  1105. $array_estensioni_ammesse = $EXTENSION_ALLOWED;
  1106. $basename = DCTL_PROJECT_PATH.$collection_id.SYS_PATH_SEP;
  1107. $regexp = '[';
  1108. foreach($array_estensioni_ammesse as $k=>$v) {
  1109. if ($k >0) $regexp .= ' | ';
  1110. $regexp .= $v;
  1111. };
  1112. $regexp .= ']';
  1113. $dPath = $basename.DCTL_MEDIA_SML;
  1114. if (!is_dir($dPath)) mkdir($dPath, CHMOD);
  1115. @chmod($dPath, CHMOD);
  1116. $dPath = $basename.DCTL_MEDIA_MED;
  1117. if (!is_dir($dPath)) mkdir($dPath, CHMOD);
  1118. @chmod($dPath, CHMOD);
  1119. $dPath = $basename.DCTL_MEDIA_BIG;
  1120. if (!is_dir($dPath)) mkdir($dPath, CHMOD);
  1121. @chmod($dPath, CHMOD);
  1122. $dPath = $basename.DCTL_MEDIA_BIG;
  1123. $variants = array();
  1124. $handle = opendir($dPath);
  1125. while ($entry = readdir($handle)) {
  1126. if (substr($entry, 0, 1) != '.') {
  1127. $variants[] = $entry;
  1128. };
  1129. };
  1130. $variants = array_values(preg_grep('/.*'.$regexp.'/', $variants));
  1131. $idx = count($variants);
  1132. sort($variants);
  1133. $fDiv0 = str_ireplace('$', '', $fDivX);
  1134. $label0 = str_ireplace('$', '', $labelX);
  1135. //putOpenCloseLevel
  1136. $resultText .= putOpenLevel($fDiv0, $loc4msg, false, 'Gestione '.$label0.' di "'.$itemName.'" ('.$idx.')', &$resultMsg);
  1137. $resultText .= '<table>';
  1138. $resultText .= '<thead>';
  1139. $resultText .= '<tr>';
  1140. $resultText .= '<th class="label">operazione</th>';
  1141. $resultText .= '<th>azione</th>';
  1142. $resultText .= '<th>risultato</th>';
  1143. $resultText .= '</tr>';
  1144. $resultText .= '</thead>';
  1145. $resultText .= '<tbody>';
  1146. /* CARICA UNA IMMAGINE */
  1147. $dPath = $basename.DCTL_MEDIA_BIG;
  1148. $resultText .= '<tr>';
  1149. $resultText .= '<td>Carica un nuovo file ...</td>';
  1150. $resultText .= '<td>';
  1151. $resultText .= '<form id="form'.$fDiv0.'" action="'.$_SERVER['SCRIPT_NAME'].'" method="'.DCTL_FORM_METHOD_POST.'" enctype="'.DCTL_FORM_ENCTYPE_POST.'">';
  1152. $resultText .= '<fieldset>';
  1153. $resultText .= '<input type="file" id="multi_file_upload" name="FILE'.$fCount.'" size="50" />';
  1154. $resultText .= '<input type="hidden" name="PATH" value="'.$dPath.'" />';
  1155. $resultText .= '<input type="hidden" name="posx" value="'.$fDiv0.'" />';
  1156. $resultText .= '<input type="hidden" name="ext" value="img" />';
  1157. $resultText .= SYS_DBL_SPACE.SYS_DBL_SPACE.'<input type="submit" name="upload" value="invia" />';
  1158. $resultText .= '<br /><strong>File da caricare</strong> (max 10): <div id="files_list"></div>
  1159. <script>
  1160. var multi_selector = new MultiSelector(document.getElementById("files_list"), 10);
  1161. multi_selector.addElement(document.getElementById("multi_file_upload") );
  1162. </script>
  1163. ';
  1164. $resultText .= '<input type="hidden" name="collection_id" value="'.$collection_id.'" />';
  1165. $resultText .= '</fieldset>';
  1166. $resultText .= '</form>';
  1167. $resultText .= '</td>';
  1168. $resultText .= '<td>&#160;</td>';
  1169. $resultText .= '</tr>';
  1170. /* VISUALIZZA LE ANTEPRIME */
  1171. $dPath = $basename.DCTL_MEDIA_BIG;
  1172. $resultText .= '<tr>';
  1173. $resultText .= '<td>Visualizza l\'anteprima di un file...<br /><br />';
  1174. $resultText .= '<form action="">';
  1175. $resultText .= '<fieldset>';
  1176. $resultText .= '<input type="text" id="mediaFilter" value="-trova-" onkeyup="var vFilter=this.value;
  1177. $(\'#mediaList li\').removeClass(\'found\');
  1178. var index = $(\'#mediaList li\').index($(\'#mediaList a\').filter(function(node){return ((this.text.toLowerCase().indexOf(vFilter)>=0)&&(vFilter!=\'\'))}).parent().addClass(\'found\'));
  1179. " />';
  1180. $resultText .= '</fieldset>';
  1181. $resultText .= '</form>';
  1182. $resultText .= '</td>';
  1183. $resultText .= '<td colspan="2">';
  1184. if (is_dir($dPath)) {
  1185. $resultText .= '<ul id="mediaList" class="trueContainer';
  1186. if (true) $resultText .= '2';
  1187. $resultText .= '">';
  1188. // $resultText .= '<script type="text/javascript" src="../js/imager.js"></script>';
  1189. // $resultText .= '<div id="motioncontainer" style="position:relative;overflow:hidden;">';
  1190. // $resultText .= '<div id="motiongallery" style="position:absolute;left:0;top:0;white-space: nowrap;">';
  1191. // $resultText .= '<span id="trueContainer">';
  1192. $tail = '';
  1193. $dPath2 = $dPath; //$dPath2 = str_ireplace(DCTL_MEDIA_SML, DCTL_MEDIA_BIG, $dPath);
  1194. $files = scandir($dPath2);
  1195. $filePattern = '/-('.WS.'*)(.*)('.WS.'*)=('.WS.'*)$('.WS.'*)-/';
  1196. if ($dPath != '') {
  1197. $entries = array();
  1198. $handle = opendir($dPath);
  1199. while ($entry = readdir($handle)) {
  1200. if (substr($entry, 0, 1) != '.') {
  1201. $entries[] = $entry;
  1202. };
  1203. };
  1204. sort($entries);
  1205. foreach($entries as $entry) {
  1206. $ext = strtolower(substr($entry, -3, 3));
  1207. if (in_array($ext, $array_estensioni_ammesse)) {
  1208. $labelval = str_ireplace('$', $entry, $filePattern);
  1209. $labelx = array_values(preg_grep($labelval, $files));
  1210. if (count($labelx)>0) {
  1211. $label = $labelx[0];
  1212. $labelx = preg_split('/('.WS.'*)=('.WS.'*)/', $label, -1);
  1213. $label = str_ireplace('-', '', $labelx[0]);
  1214. } else {
  1215. $label = $entry;
  1216. };
  1217. if ($label != $entry) {
  1218. if (substr($label, 0, strlen($collection_id)) != $collection_id) {
  1219. $label = $collection_id.'-'.$label;
  1220. };
  1221. rename($dPath.$entry, $dPath.$label);
  1222. rename($dPath2.$entry, $dPath2.$label);
  1223. $entry = $label;
  1224. };
  1225. $value = $dPath.$entry;
  1226. $tail2 = '';
  1227. $tail2 .= '<li id="'.$entry.'"><a href="javascript:indexAjax(\'load_preview\', \''.$fDiv0.'-img\', \''.$collection_id.'\', \'\', \'url='.str_ireplace(FS_BASE_PATH, HOST_BASE_PATH, $value).'\', \'posx='.$fDiv0.'\');" title="'.$label.'">';
  1228. $tail2 .= $label;
  1229. $tail2 .= '</a></li>';
  1230. $tail = $tail.$tail2;
  1231. };
  1232. };
  1233. };
  1234. // $resultText .= '</span>';
  1235. $resultText .= $tail;
  1236. $resultText .= '</ul>';
  1237. $resultText .= '</div>';
  1238. $resultText .= '</div>';
  1239. $resultText .= '<div id="'.$fDiv0.'-img">&#160;</div>';
  1240. };
  1241. $resultText .= '</td>';
  1242. $resultText .= '</tr>';
  1243. if (DCTL_USER_IS_ADMIN) {
  1244. /* RIGENERA LE ANTEPRIME */
  1245. $dPath = $basename.DCTL_MEDIA_BIG;
  1246. $resultText .= '<tr>';
  1247. $resultText .= '<td>Rigenera le anteprime...</td>';
  1248. $resultText .= '<td>'.'<a onclick="javascript: doProgress();" href="'.$_SERVER['SCRIPT_NAME'].'?createPreview='.str_ireplace(FS_BASE_PATH, HOST_BASE_PATH, $dPath).'&amp;collection_id='.$collection_id.'&amp;posx='.$fDivX.'" title="(???)">Procedi...</a>'.'</td>';
  1249. $resultText .= '<td>'.'&#160;'.'</td>';
  1250. $resultText .= '</tr>';
  1251. };
  1252. $resultText .= '</tbody>';
  1253. $resultText .= '</table>';
  1254. $resultText .= '<br /></div>';
  1255. return $resultText;
  1256. };
  1257. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1258. function getManagementOfXML ($fSelectorX, $fDivX, $labelX, $collection_id, $package_id, $itemName, $errorInDownload, $loc4msg, &$fCount, $resultMsg) {
  1259. $resultText = '';
  1260. $isMultiPart = stripos($fSelectorX, '$') !== FALSE;
  1261. $basename = DCTL_PROJECT_PATH.$collection_id;
  1262. if ($package_id != '') {
  1263. $basename .= SYS_PATH_SEP.$package_id;
  1264. };
  1265. $dPath = $basename;
  1266. $regexp = str_ireplace(DCTL_PACKAGE_BODY_REGEXP1, DCTL_PACKAGE_BODY_REGEXP2, $fSelectorX);
  1267. $variants = array();
  1268. $handle = opendir($dPath);
  1269. while ($entry = readdir($handle)) {
  1270. if (substr($entry, 0, 1) != '.') {
  1271. if (($entry==DCTL_PACKAGE_FRONT)||($entry==DCTL_PACKAGE_BACK)||($isMultiPart)) {
  1272. $variants[] = $entry;
  1273. };
  1274. };
  1275. };
  1276. $variants = array_values(preg_grep('/^'.$regexp.'/', $variants));
  1277. $idx = count($variants);
  1278. sort($variants);
  1279. $fDiv0 = str_ireplace('$', '', $fDivX);
  1280. $label0 = str_ireplace('$', '', $labelX);
  1281. $resultText .= putOpenCloseLevel($fDiv0, $loc4msg, false, 'Gestione '.$label0.' di "'.$itemName.'" ('.$idx.')', &$resultMsg);
  1282. if ($errorInDownload && ($loc4msg == $fDiv0)) {
  1283. $resultText .= '<span class="error">ATTENZIONE: il file "'.$_REQUEST['file'].'" di "'.$itemName.'" è già stato bloccato... download annullato!</span><br />';
  1284. };
  1285. $resultText .= '<table>';
  1286. $resultText .= '<thead>';
  1287. $resultText .= '<tr>';
  1288. $resultText .= '<th class="label">nome</th>';
  1289. $resultText .= '<th>ult. modifica</th>';
  1290. $resultText .= '<th>operazioni</th>';
  1291. $resultText .= '<th>utente</th>';
  1292. $resultText .= '</tr>';
  1293. $resultText .= '</thead>';
  1294. $resultText .= '<tbody>';
  1295. foreach($variants as $vKey=>$fSelector) {
  1296. switch ($vKey) {
  1297. case 0:
  1298. $label = str_ireplace('$', 'iniziale <em>(front)</em>', $labelX);
  1299. break;
  1300. case (count($variants)-1):
  1301. $vKey = 999;
  1302. $label = str_ireplace('$', 'finale <em>(back)</em>', $labelX);
  1303. break;
  1304. default:
  1305. $idx = sprintf("%03d", $vKey);
  1306. $label = str_ireplace('$', $idx.' <em>(body)</em>', $labelX);
  1307. break;
  1308. };
  1309. $idx = sprintf("%03d", $vKey);
  1310. $fDiv = str_ireplace('$', $vKey, $fDivX);
  1311. $fSelector = str_ireplace('$', $idx, $fSelectorX);
  1312. $fPath = $basename.SYS_PATH_SEP.$fSelector;
  1313. $who = '';
  1314. $content = array();
  1315. $label .= '<br/><span class="morelink">';
  1316. getPartRecord($fPath, &$packageRecord);
  1317. if($packageRecord['part_work']!='') {
  1318. $label .= $packageRecord['part_work'];
  1319. } else {
  1320. $label .= '???';
  1321. };
  1322. $label .= '</span>';
  1323. $isLocked = checkIfLocked ($fPath, &$who, &$content);
  1324. $resultText .= '<tr>';
  1325. $resultText .= '<td>'.$label.'</td>';
  1326. if (is_file($fPath)) {
  1327. $resultText .= '<td>'.date ("d-m-y H:i", filemtime($fPath)).'</td>';
  1328. if ($isLocked) {
  1329. if ($who == DCTL_USER_ID) {
  1330. $fCount++;
  1331. $resultText .= '<td>';
  1332. $resultText .= '<form id="form'.$fDiv0.'" action="'.$_SERVER['SCRIPT_NAME'].'" method="'.DCTL_FORM_METHOD_POST.'" enctype="'.DCTL_FORM_ENCTYPE_POST.'">';
  1333. $resultText .= '<fieldset>';
  1334. $resultText .= '<span class="dctl_ok"><img src="'.DCTL_IMAGES.'file_alert.gif" alt="(alert icon)" />&#160;'.'Ricarica file</span><br />';
  1335. $resultText .= '<input type="file" name="FILE'.$fCount.'" value="'.$fPath.'" />';
  1336. $resultText .= '<input type="hidden" name="PATH" value="'.$fPath.'" />';
  1337. $resultText .= '<input type="hidden" name="ext" value="txt" />';
  1338. $resultText .= SYS_DBL_SPACE.'<input type="submit" name="upload" value="invia" />';
  1339. $resultText .= '</fieldset>';
  1340. $resultText .= '<br />';
  1341. $resultText .= '<fieldset>';
  1342. $resultText .= '<span class="dctl_ko"><img src="'.DCTL_IMAGES.'file_alert.gif" alt="(alert icon)" />&#160;'.'Sblocca il file senza ricaricare</span>';
  1343. $resultText .= '<input type="hidden" name="PATH" value="'.$fPath.'" />';
  1344. $resultText .= '<input type="hidden" name="ext" value="txt" />';
  1345. $resultText .= SYS_DBL_SPACE.'<input type="submit" name="reset" value="sblocca" />';
  1346. $resultText .= '</fieldset>';
  1347. $resultText .= '<fieldset>';
  1348. $resultText .= '<input type="hidden" name="posx" value="'.$fDiv0.'" />';
  1349. $resultText .= '<input type="hidden" name="collection_id" value="'.$collection_id.'" />';
  1350. $resultText .= '<input type="hidden" name="package_id" value="'.$package_id.'" />';
  1351. $resultText .= '</fieldset>';
  1352. $resultText .= '</form>';
  1353. $resultText .= '</td>';
  1354. $resultText .= '<td><span class="dctl_ok">'.$who.'</span></td>';
  1355. } else {
  1356. $resultText .= '<td><span class="dctl_ko"><img src="'.DCTL_IMAGES.'page_lock.gif" alt="(locked file icon)" />&#160;&#160;'.'File bloccato</span></td>';
  1357. $resultText .= '<td><span class="dctl_ko">'.$who.'</span></td>';
  1358. };
  1359. } else {
  1360. $resultText .= '<td id="xml-'.$fDiv.'">';
  1361. $resultText .= '<a href="indexDownload.php?';
  1362. $resultText .= 'file='.$fPath.'&amp;';
  1363. $resultText .= 'lock=yes&amp;';
  1364. $resultText .= 'user='.DCTL_USER_ID.'&amp;';
  1365. $resultText .= 'error=yes&amp;';
  1366. $resultText .= 'posx='.$fDiv0.'&amp;';
  1367. $resultText .= 'collection_id='.$collection_id.'&amp;';
  1368. $resultText .= 'package_id='.$package_id.'&amp;';
  1369. $resultText .= '" onclick="javascript:document.getElementById(\'xml-'.$fDiv.'\').innerHTML=\'';
  1370. $resultText .= '(bloccato)';
  1371. $resultText .= '\'';
  1372. $resultText .= '" title="scarica il file e blocca">';
  1373. $resultText .= '<img src="'.DCTL_IMAGES.'page_down.gif" alt="(download file icon)" />'.SYS_DBL_SPACE;
  1374. $resultText .= 'Scarica e blocca</a>';
  1375. $resultText .= '</td>';
  1376. $resultText .= '<td>'.'-'.'</td>';
  1377. };
  1378. } else {
  1379. $resultText .= '<td>'.'<span class="error">(missing)</span>'.'</td>';
  1380. $resultText .= '<td>'.'-'.'</td>';
  1381. $resultText .= '<td>'.'-'.'</td>';
  1382. };
  1383. $resultText .= '</tr>';
  1384. };
  1385. if ($isMultiPart) {
  1386. if (DCTL_USER_IS_EDITOR) {
  1387. $resultText .= '<tr>';
  1388. $resultText .= '<td>&#160;</td>';
  1389. $resultText .= '<td>&#160;</td>';
  1390. $resultText .= '<td>';
  1391. $resultText .= '<form id="form'.$fDiv0.'" action="'.$_SERVER['SCRIPT_NAME'].'" method="'.DCTL_FORM_METHOD.'" enctype="'.DCTL_FORM_ENCTYPE.'">';
  1392. $resultText .= '<fieldset>';
  1393. $resultText .= '<input name="createPart" type="submit" value="Crea nuova Parte..." />';
  1394. $resultText .= '<input type="hidden" name="posx" value="'.$fDiv0.'" />';
  1395. $resultText .= '<input type="hidden" name="collection_id" value="'.$collection_id.'" />';
  1396. $resultText .= '<input type="hidden" name="package_id" value="'.$package_id.'" />';
  1397. $resultText .= '</fieldset>';
  1398. $resultText .= '</form>';
  1399. $resultText .= '</td>';
  1400. $resultText .= '<td>&#160;</td>';
  1401. $resultText .= '</tr>';
  1402. };
  1403. };
  1404. $resultText .= '</tbody>';
  1405. $resultText .= '</table>';
  1406. $resultText .= '<br /></div>';
  1407. return $resultText;
  1408. };
  1409. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1410. function getCollectionRecord ($thePath, &$collectionRecord) {
  1411. $collectionRecord = array();
  1412. $collectionRecord['collection_id'] = '';
  1413. $collectionRecord['collection_short'] = '';
  1414. $collectionRecord['collection_work'] = '';
  1415. $collectionRecord['collection_full'] = '';
  1416. $header = $thePath.DCTL_FILE_HEADER;
  1417. if (is_file($header)) {
  1418. $contents = cleanUpIndentation(file_get_contents($header));
  1419. $lines = explode('<!ENTITY ', $contents);
  1420. $field = 'collection_id';
  1421. $linex = array_values(preg_grep('/'.$field.'.*/', $lines));
  1422. $linex = explode('"', $linex[0]);
  1423. $collection_id = strtolower(basename($linex[1]));
  1424. $collection_id = normalize($collection_id);
  1425. $collectionRecord['collection_id'] = $collection_id;
  1426. $field = 'collection_short';
  1427. $linex = array_values(preg_grep('/'.$field.'.*/', $lines));
  1428. $linex = explode('"', $linex[0]);
  1429. // $collection_short = strtolower(basename($linex[1]));
  1430. // $collection_short = strtoupper(normalize($collection_short));
  1431. // $collectionRecord['collection_short'] = $collection_short;
  1432. $collectionRecord['collection_short'] = cleanWebString($linex[1]);
  1433. $field = 'collection_work';
  1434. $linex = array_values(preg_grep('/'.$field.'.*/', $lines));
  1435. $linex = explode('"', $linex[0]);
  1436. $collectionRecord['collection_work'] = cleanWebString($linex[1]);
  1437. $collectionRecord['collection_full'] = cleanWebString($collectionRecord['collection_short'].': '.$collectionRecord['collection_work'], FIELD_STRING_LENGTH).SYS_DBL_SPACE;
  1438. };
  1439. };
  1440. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1441. function getPackageRecord ($thePath, &$packageRecord) {
  1442. $packageRecord = array();
  1443. $packageRecord['package_id'] = '';
  1444. $packageRecord['package_ext'] = '';
  1445. $packageRecord['package_short'] = '';
  1446. $packageRecord['package_work'] = '';
  1447. $packageRecord['package_full'] = '';
  1448. $header = $thePath.DCTL_FILE_HEADER;
  1449. if (is_file($header)) {
  1450. $contents = cleanUpIndentation(file_get_contents($header));
  1451. $lines = explode('<!ENTITY ', $contents);
  1452. $field = 'package_id';
  1453. $linex = array_values(preg_grep('/'.$field.'.*/', $lines));
  1454. $linex = explode('"', $linex[0]);
  1455. $package_id = strtolower(basename($linex[1]));
  1456. $package_id = normalize($package_id);
  1457. $packageRecord['package_id'] = $package_id;
  1458. $package_ext = substr($package_id, -4, 4);
  1459. $packageRecord['package_ext'] = $package_ext;
  1460. $field = 'package_short';
  1461. $linex = array_values(preg_grep('/'.$field.'.*/', $lines));
  1462. $linex = explode('"', $linex[0]);
  1463. // $package_short = strtolower(basename($linex[1]));
  1464. // $package_short = strtoupper(normalize($package_short));
  1465. // $packageRecord['package_short'] = $package_short;
  1466. $packageRecord['package_short'] = cleanWebString($linex[1]);
  1467. $field = 'package_work';
  1468. $linex = array_values(preg_grep('/'.$field.'.*/', $lines));
  1469. $linex = explode('"', $linex[0]);
  1470. $packageRecord['package_work'] = cleanWebString($linex[1]);
  1471. $packageRecord['package_full'] = cleanWebString($packageRecord['package_id'].': '.$packageRecord['package_short'], FIELD_STRING_LENGTH).SYS_DBL_SPACE;
  1472. };
  1473. };
  1474. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1475. function getMediaRecord ($thePath, &$mediaRecord) {
  1476. $mediaRecord = array();
  1477. $mediaRecord['media_id'] = '';
  1478. $mediaRecord['media_short'] = '';
  1479. $mediaRecord['media_work'] = '';
  1480. $media_id = basename($thePath);
  1481. $media_id = normalize($media_id);
  1482. $mediaRecord['media_id'] = $media_id;
  1483. $media_short = basename($thePath);
  1484. $media_short = normalize($media_short);
  1485. $mediaRecord['media_short'] = cleanWebString($media_short);
  1486. $media_work = basename($thePath);
  1487. $media_work = normalize($media_work);
  1488. $mediaRecord['media_work'] = cleanWebString($media_work);
  1489. };
  1490. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1491. function getPartRecord ($thePath, &$partRecord) {
  1492. $partRecord = array();
  1493. $partRecord['part_id'] = '';
  1494. $partRecord['part_short'] = '';
  1495. $partRecord['part_work'] = '';
  1496. $resultXML = basename($thePath);
  1497. if (is_file($thePath)) {
  1498. forceUTF8($thePath);
  1499. $simplexml = @simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER); //
  1500. if (!$simplexml) {
  1501. $resultXML = array(0=>'*** File con errori XML ***');
  1502. } else {
  1503. $namespaces = $simplexml->getDocNamespaces();
  1504. foreach ($namespaces as $nsk=>$ns) {
  1505. if ($nsk == '') $nsk = 'tei';
  1506. $simplexml->registerXPathNamespace($nsk, $ns);
  1507. };
  1508. $resultXML = $simplexml->xpath('//tei:div[./tei:head/tei:index/tei:term != ""][1]/tei:head/tei:index/tei:term[. != ""][1]');
  1509. if (!isset($resultXML[0]))
  1510. $resultXML = $simplexml->xpath('//tei:div[./tei:head != ""][1]/tei:head[. != ""][1]');
  1511. };
  1512. };
  1513. $part_id = basename($thePath);
  1514. $part_id = normalize($part_id);
  1515. $partRecord['part_id'] = $part_id;
  1516. $part_short = basename($thePath);
  1517. $part_short = normalize($part_short);
  1518. $partRecord['part_short'] = cleanWebString($part_short);
  1519. $part_work = (string)$resultXML[0];
  1520. $partRecord['part_work'] = cleanWebString($part_work, 80);
  1521. };
  1522. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1523. function getItemRecord ($thePath, &$itemRecord, $theLabel='') {
  1524. $itemRecord = array();
  1525. $itemRecord['item_id'] = '';
  1526. $itemRecord['item_short'] = '';
  1527. $itemRecord['item_work'] = '';
  1528. $item_id = basename($thePath);
  1529. $item_id = normalize($item_id);
  1530. $itemRecord['item_id'] = $item_id;
  1531. $item_short = $item_id;
  1532. $itemRecord['item_short'] = $item_short;
  1533. $item_work = $theLabel;
  1534. $itemRecord['item_work'] = cleanWebString($item_work,18);
  1535. if (checkIfLocked (dirname($thePath), &$who, &$content)) {
  1536. $itemRecord['item_id'] = '';
  1537. $itemRecord['item_work'] = 'in use by '.$who;
  1538. };
  1539. };
  1540. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1541. function getImageRecord ($thePath, &$imageRecord, $theLabel='') {
  1542. $imageRecord = array();
  1543. $imageRecord['image_id'] = '';
  1544. $imageRecord['image_short'] = '';
  1545. $imageRecord['image_work'] = '';
  1546. $image_id = basename($thePath);
  1547. if (stripos($image_id, '-') === false) {
  1548. $image_id = basename(dirname($thePath)).'-'.$image_id;
  1549. };
  1550. $image_id = normalize($image_id);
  1551. $imageRecord['image_id'] = $image_id;
  1552. $image_short = $image_id;
  1553. $imageRecord['image_short'] = $image_short;
  1554. $image_work = $theLabel;
  1555. $imageRecord['image_work'] = cleanWebString($image_work); // , 18
  1556. $collection_id = '???';
  1557. };
  1558. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1559. function getCollectionList ($thePath, &$collectionList, $withEmpty=false) {
  1560. $collectionList = array();
  1561. if ($withEmpty) {
  1562. $collectionList['collection_id'][] = '';
  1563. $collectionList['collection_short'][] = '';
  1564. $collectionList['collection_full'][] = '';
  1565. $collectionList['path'][] = '';
  1566. };
  1567. $collectionRecord = array();
  1568. if ($thePath != '') {
  1569. $entries = array();
  1570. $handle = opendir($thePath);
  1571. while ($entry = readdir($handle)) {
  1572. if (substr($entry, 0, 1) != '.') {
  1573. if (! preg_match('/^'.DCTL_RESERVED_PREFIX.'/',$entry)) {
  1574. $entries[] = $entry;
  1575. };
  1576. };
  1577. };
  1578. sort($entries);
  1579. foreach($entries as $entry) {
  1580. $full = $thePath.$entry.SYS_PATH_SEP;
  1581. if (is_dir($full)) {
  1582. getCollectionRecord ($full, &$collectionRecord);
  1583. $collectionList['collection_id'][] = $collectionRecord['collection_id'];
  1584. $collectionList['collection_short'][] = $collectionRecord['collection_short'];
  1585. $collectionList['collection_full'][] = $collectionRecord['collection_full'];
  1586. $collectionList['path'][] = $full;
  1587. };
  1588. };
  1589. };
  1590. };
  1591. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1592. function getPackageList ($thePath, &$packageList, $withEmpty=false) {
  1593. $packageList = array();
  1594. if ($withEmpty) {
  1595. $packageList['package_id'][] = '';
  1596. $packageList['package_ext'][] = '';
  1597. $packageList['package_short'][] = '';
  1598. $packageList['package_full'][] = '';
  1599. $packageList['path'][] = '';
  1600. };
  1601. $packageRecord = array();
  1602. if ($thePath != '') {
  1603. $entries = array();
  1604. $handle = opendir($thePath);
  1605. while ($entry = readdir($handle)) {
  1606. if (substr($entry, 0, 1) != '.') {
  1607. if (! preg_match('/^'.DCTL_RESERVED_PREFIX.'/',$entry)) {
  1608. $entries[] = $entry;
  1609. };
  1610. };
  1611. };
  1612. sort($entries);
  1613. foreach($entries as $entry) {
  1614. $full = $thePath.$entry.SYS_PATH_SEP;
  1615. if (is_dir($full)) {
  1616. getPackageRecord ($full, &$packageRecord);
  1617. $packageList['package_id'][] = $packageRecord['package_id'];
  1618. $packageList['package_ext'][] = $packageRecord['package_ext'];
  1619. $packageList['package_short'][] = $packageRecord['package_short'];
  1620. $packageList['package_full'][] = $packageRecord['package_full'];
  1621. $packageList['path'][] = $full;
  1622. };
  1623. };
  1624. };
  1625. };
  1626. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1627. function getMediaList ($thePath, &$mediaList, $withEmpty=false) {
  1628. $mediaList = array();
  1629. if ($withEmpty) {
  1630. $mediaList['media_id'][] = '';
  1631. $mediaList['media_short'][] = '';
  1632. $mediaList['path'][] = '';
  1633. };
  1634. $mediaRecord = array();
  1635. if ($thePath != '') {
  1636. $entries = array();
  1637. $handle = opendir($thePath);
  1638. while ($entry = readdir($handle)) {
  1639. if (substr($entry, 0, 1) != '.') {
  1640. if (! preg_match('/^'.DCTL_RESERVED_PREFIX.'/',$entry)) {
  1641. $entries[] = $entry;
  1642. };
  1643. };
  1644. };
  1645. sort($entries);
  1646. foreach($entries as $entry) {
  1647. $full = $thePath.$entry.SYS_PATH_SEP;
  1648. if (is_dir($full)) {
  1649. getMediaRecord ($full, &$mediaRecord);
  1650. $mediaList['media_id'][] = $mediaRecord['media_id'];
  1651. $mediaList['media_short'][] = $mediaRecord['media_short'];
  1652. $mediaList['path'][] = $full;
  1653. };
  1654. };
  1655. };
  1656. };
  1657. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1658. function getPartList ($thePath, &$partList, $withEmpty=false) {
  1659. $partList = array();
  1660. if ($withEmpty) {
  1661. $partList['part_id'][] = '';
  1662. $partList['part_short'][] = '';
  1663. $partList['path'][] = '';
  1664. };
  1665. $partRecord = array();
  1666. if ($thePath != '') {
  1667. $entries = array();
  1668. $handle = opendir($thePath);
  1669. while ($entry = readdir($handle)) {
  1670. if (substr($entry, 0, 1) != '.') {
  1671. if (! preg_match('/^'.DCTL_RESERVED_PREFIX.'/',$entry)) {
  1672. $entries[] = $entry;
  1673. };
  1674. };
  1675. };
  1676. sort($entries);
  1677. foreach($entries as $entry) {
  1678. if (($entry == DCTL_PACKAGE_FRONT) || (preg_match('/^'.str_ireplace(DCTL_PACKAGE_BODY_REGEXP1, DCTL_PACKAGE_BODY_REGEXP2, DCTL_PACKAGE_BODY).'/', $entry)) || ($entry == DCTL_PACKAGE_BACK)) {
  1679. $full = $thePath.$entry;
  1680. getPartRecord ($full, &$partRecord);
  1681. $partList['part_id'][] = $partRecord['part_id'];
  1682. $partList['part_short'][] = $partRecord['part_short'];
  1683. $partList['path'][] = $full;
  1684. };
  1685. };
  1686. };
  1687. };
  1688. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1689. function getItemList ($thePath, &$itemList, $what, $withEmpty=false) {
  1690. $itemList = array();
  1691. if ($withEmpty) {
  1692. $itemList['item_id'][] = '';
  1693. $itemList['item_short'][] = '';
  1694. $itemList['path'][] = '';
  1695. };
  1696. $itemRecord = array();
  1697. if ($thePath[strlen($thePath)-1] == SYS_PATH_SEP) $thePath = dirname($thePath.'xxx');
  1698. if ($thePath != '') {
  1699. if (is_file($thePath)) {
  1700. forceUTF8($thePath);
  1701. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  1702. $simplexml = simplexml_load_string(preg_replace('/xml\:id/','id',$simplexml->asXML()), 'SimpleXMLElement');
  1703. $namespaces = $simplexml->getDocNamespaces();
  1704. foreach ($namespaces as $nsk=>$ns) {
  1705. if ($nsk == '') $nsk = 'tei';
  1706. $simplexml->registerXPathNamespace($nsk, $ns);
  1707. };
  1708. $xpath = '//tei:text//*[@id != ""]';
  1709. switch ($what) {
  1710. case 'lnk':
  1711. break;
  1712. case 'map':
  1713. $xpath .= '[contains(@ana, "key_item")]';
  1714. break;
  1715. };
  1716. $resultXML = $simplexml->xpath($xpath);
  1717. foreach ($resultXML as $k=>$v) {
  1718. $entry = $v['id'];
  1719. $full = $thePath.SYS_PATH_SEP.$entry;
  1720. getItemRecord ($full, &$itemRecord, cleanWebString($v->asXML()));
  1721. $itemList['item_id'][] = $itemRecord['item_id'];
  1722. $itemList['item_short'][] = $itemRecord['item_work'];
  1723. $itemList['path'][] = $full;
  1724. };
  1725. };
  1726. };
  1727. // asort($itemList);
  1728. return count($itemList);
  1729. };
  1730. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1731. function getImageList ($thePath, &$imageList, $withEmpty=false) {
  1732. $imageList = array();
  1733. if ($withEmpty) {
  1734. $imageList['image_id'][] = '';
  1735. $imageList['image_short'][] = '';
  1736. $imageList['image_work'][] = '';
  1737. $imageList['path'][] = '';
  1738. };
  1739. $imageRecord = array();
  1740. if ($thePath[strlen($thePath)-1] == SYS_PATH_SEP) $thePath = dirname($thePath.'xxx');
  1741. if ($thePath != '') {
  1742. if (is_file($thePath)) {
  1743. forceUTF8($thePath);
  1744. $simplexml = simplexml_load_file($thePath, 'SimpleXMLElement', DCTL_XML_LOADER);
  1745. $simplexml = simplexml_load_string(preg_replace('/xml\:id/','id',$simplexml->asXML()), 'SimpleXMLElement');
  1746. $namespaces = $simplexml->getDocNamespaces();
  1747. foreach ($namespaces as $nsk=>$ns) {
  1748. if ($nsk == '') $nsk = 'tei';
  1749. $simplexml->registerXPathNamespace($nsk, $ns);
  1750. };
  1751. $xpath = '//tei:text//tei:figure';
  1752. $resultXML = $simplexml->xpath($xpath);
  1753. foreach ($resultXML as $k=>$v) {
  1754. $entry = $v->graphic['url'];
  1755. $full = $thePath.SYS_PATH_SEP.$entry;
  1756. getImageRecord ($full, &$imageRecord, cleanWebString($v->figDesc->asXML()));
  1757. $imageList['image_id'][] = $imageRecord['image_id'];
  1758. $imageList['image_short'][] = $imageRecord['image_short'];
  1759. $imageList['image_work'][] = $imageRecord['image_work'];
  1760. $imageList['path'][] = $full;
  1761. };
  1762. };
  1763. };
  1764. // asort($imageList);
  1765. return count($imageList);
  1766. };
  1767. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1768. function publish_transformXML($entry, $fullsrc, $fulldst, $xsl_proc, &$operationsPublish, &$toPublish) {
  1769. $text = '';
  1770. $prosecute = FALSE;
  1771. $basename = basename(dirname($fullsrc));
  1772. $uppername = basename(dirname(dirname($fullsrc)));
  1773. $operationsPublish .= '&gt; processo "'.$basename.'"...';
  1774. $level = count(explode(SYS_PATH_SEP, str_ireplace(DCTL_PROJECT_PATH, '', $fullsrc)));
  1775. switch ($level) {
  1776. case 2 : // COLLECTION
  1777. switch ($entry) {
  1778. case DCTL_FILE_BUILDER:
  1779. $fTarget = $basename.DCTL_RESERVED_INFIX.DCTL_RESERVED_PREFIX.$basename.'.xml';
  1780. $prosecute = TRUE;
  1781. break;
  1782. case DCTL_FILE_LINKER:
  1783. case DCTL_FILE_MAPPER:
  1784. $fTarget = $basename.DCTL_RESERVED_INFIX.$entry;
  1785. $prosecute = TRUE;
  1786. break;
  1787. };
  1788. break;
  1789. case 3 : // PACKAGE
  1790. switch ($entry) {
  1791. case DCTL_FILE_BUILDER:
  1792. copy(DCTL_SETTINGS_TEMPLATES_PACKAGE.DCTL_FILE_BUILDER, $fullsrc);
  1793. @chmod($fullsrc, CHMOD);
  1794. $fTarget = $uppername.DCTL_RESERVED_INFIX.$basename.'.xml';
  1795. $prosecute = TRUE;
  1796. break;
  1797. };
  1798. break;
  1799. };
  1800. if ($prosecute) {
  1801. $xml_path = $fullsrc;
  1802. try {
  1803. if (isset($xml_dom)) unset($xml_dom);
  1804. $xml_dom = new DOMDocument('1.0', 'UTF-8');
  1805. $xml_dom->preserveWhiteSpace = false;
  1806. forceUTF8($xml_path);
  1807. $xml_dom->load($xml_path, DCTL_XML_LOADER);
  1808. } catch (Exception $e) {
  1809. $operationsPublish .= '<span class="error">impossibile caricare XML "'.$entry.'"... {'.$e.'}</span><br />';
  1810. $prosecute = FALSE;
  1811. };
  1812. if ($prosecute) {
  1813. try {
  1814. $text .= $xsl_proc->transformToXML($xml_dom);
  1815. } catch (Exception $e) {
  1816. $operationsPublish .= '<span class="error">impossibile trasformare XML "'.$entry.'"... {'.$e.'}</span><br />';
  1817. $prosecute = FALSE;
  1818. };
  1819. };
  1820. if ($prosecute) {
  1821. $text = str_ireplace('xmlns=""','', $text);
  1822. if ($text != '') {
  1823. try {
  1824. $fulldst = dirname($fulldst).SYS_PATH_SEP.$fTarget;
  1825. $fd = fopen ($fulldst, "wb");
  1826. $out = fwrite ($fd, forceUTF8($text));
  1827. fclose ($fd);
  1828. @chmod($fulldst, CHMOD);
  1829. $prosecute = TRUE;
  1830. $toPublish[] = $fulldst;
  1831. } catch (Exception $e) {
  1832. $operationsPublish .= '<span class="error">impossibile riscrivere XML "'.$entry.'"... {'.$e.'}</span><br />';
  1833. $prosecute = FALSE;
  1834. };
  1835. } else {
  1836. $operationsPublish .= '<span class="error">impossibile riscrivere XML "'.$entry.'"... {'.$e.'}</span><br />';
  1837. $prosecute = FALSE;
  1838. };
  1839. } else {
  1840. $operationsPublish .= '<span class="error">impossibile riscrivere XML "'.$entry.'"... {'.$e.'}</span><br />';
  1841. $prosecute = FALSE;
  1842. };
  1843. };
  1844. if($prosecute) $operationsPublish .= 'ok<br />';
  1845. hardFlush(&$operationsPublish);
  1846. return TRUE && $prosecute;
  1847. };
  1848. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1849. function dctl_insertContent ($complete_id, $param) {
  1850. $complete_id = explode( '-', $complete_id);
  1851. $collection_id = $complete_id[0];
  1852. $package_id = $complete_id[1];
  1853. $text = '';
  1854. $fSelectorX = trim($param);
  1855. $fSelectorX = str_ireplace('"', '', $fSelectorX);
  1856. $fSelectorX = str_ireplace('item=', '', $fSelectorX);
  1857. $dPath = DCTL_PROJECT_PATH.$collection_id;
  1858. if ($package_id != '') {
  1859. $dPath .= SYS_PATH_SEP.$package_id;
  1860. };
  1861. $isMultiPart = stripos($fSelectorX, '$') !== FALSE;
  1862. if ($isMultiPart) {
  1863. $regexp = str_ireplace(DCTL_PACKAGE_BODY_REGEXP1, DCTL_PACKAGE_BODY_REGEXP2, $fSelectorX);
  1864. } else {
  1865. $regexp = $fSelectorX;
  1866. };
  1867. $variants = array();
  1868. if (is_dir($dPath)) {
  1869. $handle = opendir($dPath);
  1870. while ($entry = readdir($handle)) {
  1871. if (substr($entry, 0, 1) != '.') {
  1872. $variants[] = $entry;
  1873. };
  1874. };
  1875. };
  1876. $variants = array_values(preg_grep('/^'.$regexp.'/', $variants));
  1877. sort($variants);
  1878. $max = count($variants)-1;
  1879. foreach($variants as $vKey=>$fSelector) {
  1880. if ((!$isMultiPart) || ($isMultiPart && (($vKey>0) && ($vKey<$max)))) {
  1881. $fPath = $dPath.SYS_PATH_SEP.$fSelector;
  1882. $textContent = cleanUpIndentation(charset_decode_utf_8(file_get_contents($fPath)));
  1883. $header = '<!-- %BEGIN% -->';
  1884. $textContent = substr($textContent, stripos($textContent, $header)+strlen($header));
  1885. $footer = '<!-- %END% -->';
  1886. $textContent = substr($textContent, 0, stripos($textContent, $footer));
  1887. $textContent = preg_replace('/(<!--'.WS.'*BEGIN'.WS.'*-->)/', '', $textContent);
  1888. $textContent = preg_replace('/(<!--'.WS.'*END'.WS.'*-->)/', '', $textContent);
  1889. $textContent = preg_replace('/'.WS.'+/', ' ', $textContent);
  1890. $textContent = forceUTF8($textContent);
  1891. $checkContent = preg_replace('/\w+:(\w+)/','$1',$textContent);
  1892. $checkContent = '<?xml version="1.0" encoding="UTF-8" ?><test>'.translateLiteral2NumericEntities($checkContent).'</test>';
  1893. if ($e=simplexml_load_string($checkContent, 'SimpleXMLElement', DCTL_XML_LOADER)) {
  1894. $checkChildren = count($e->children());
  1895. if ($checkChildren<1) {
  1896. $textContent = '<div type="part" />';
  1897. };
  1898. };
  1899. $text .= $textContent;
  1900. };
  1901. };
  1902. return strval($text);
  1903. };
  1904. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1905. function translateLiteral2NumericEntities($xmlSource, $reverse =
  1906. FALSE) {
  1907. static $literal2NumericEntity;
  1908. if (empty($literal2NumericEntity)) {
  1909. $transTbl = get_html_translation_table(HTML_ENTITIES);
  1910. foreach ($transTbl as $char => $entity) {
  1911. if (strpos('&"<>', $char) !== FALSE) continue;
  1912. $literal2NumericEntity[$entity] = '&#'.ord($char).';';
  1913. };
  1914. };
  1915. if ($reverse) {
  1916. return strtr($xmlSource, array_flip($literal2NumericEntity));
  1917. } else {
  1918. return strtr($xmlSource, $literal2NumericEntity);
  1919. };
  1920. };
  1921. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1922. function publish_recurseContents($pathFrom, $collName, $packName, $xsl_proc, &$operationsPublish, &$toPublish) {
  1923. hardFlush(&$operationsPublish);
  1924. $prosecute = false;
  1925. $pathTo = DCTL_PUBLISH;
  1926. $handle = opendir($pathFrom);
  1927. $basex = basename($pathFrom);
  1928. if ($basex==$collName) {
  1929. // IN COLLECTION
  1930. // BUILDER
  1931. $fullsrc = DCTL_SETTINGS_TEMPLATES_COLLECTION.DCTL_FILE_BUILDER;
  1932. $fulldst = DCTL_PROJECT_PATH.$collName.SYS_PATH_SEP.DCTL_FILE_BUILDER;
  1933. copy($fullsrc, $fulldst);
  1934. @chmod($fulldst, CHMOD);
  1935. } else {
  1936. if (($packName=='')||($basex==$packName)) {
  1937. // IN PACKAGE
  1938. if ($basex==$packName) {
  1939. // BUILDER
  1940. $fullsrc = DCTL_SETTINGS_TEMPLATES_PACKAGE.DCTL_FILE_BUILDER;
  1941. $fulldst = DCTL_PROJECT_PATH.$collName.SYS_PATH_SEP.$packName.SYS_PATH_SEP.DCTL_FILE_BUILDER;
  1942. copy($fullsrc, $fulldst);
  1943. @chmod($fulldst, CHMOD);
  1944. };
  1945. };
  1946. };
  1947. while ($entry = readdir($handle)) {
  1948. if (substr($entry, 0, 1) != '.') {
  1949. $fullsrc = $pathFrom.SYS_PATH_SEP.$entry;
  1950. $fulldst = $pathTo.SYS_PATH_SEP.$entry;
  1951. switch ($entry) {
  1952. case (basename(DCTL_MEDIA)):
  1953. case (basename(DCTL_MEDIA_SML)):
  1954. case (basename(DCTL_MEDIA_MED)):
  1955. case (basename(DCTL_MEDIA_BIG)):
  1956. $prosecute = TRUE;
  1957. break;
  1958. case DCTL_FILE_BUILDER:
  1959. case DCTL_FILE_LINKER:
  1960. case DCTL_FILE_MAPPER:
  1961. $prosecute = publish_transformXML($entry, $fullsrc, $fulldst, $xsl_proc, &$operationsPublish, &$toPublish);
  1962. break;
  1963. default:
  1964. if ($packName != '') {
  1965. if ($packName == $entry) {
  1966. // PUBLISH SELECTED PACKAGE
  1967. $prosecute = publish_recurseContents(DCTL_PROJECT_PATH.$collName.SYS_PATH_SEP.$entry, $collName, $entry, $xsl_proc, &$operationsPublish, &$toPublish);
  1968. };
  1969. } else {
  1970. // PUBLISH SELECTED COLLECTION
  1971. if (! preg_match('/^'.DCTL_RESERVED_PREFIX.'/',$entry)) {
  1972. $prosecute = publish_recurseContents(DCTL_PROJECT_PATH.$collName.SYS_PATH_SEP.$entry, $collName, $entry, $xsl_proc, &$operationsPublish, &$toPublish);
  1973. };
  1974. };
  1975. break;
  1976. };
  1977. };
  1978. };
  1979. return TRUE && $prosecute;
  1980. };
  1981. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1982. function publish_recurseMedia($pathFrom, $pathTo, &$operationsPublish) {
  1983. hardFlush(&$operationsPublish);
  1984. $prosecute = false;
  1985. if (is_dir($pathFrom)) {
  1986. if (!is_dir($pathTo)) mkdir($pathTo, CHMOD);
  1987. @chmod($pathTo, CHMOD);
  1988. $handle = opendir($pathFrom);
  1989. $basex = basename($pathFrom);
  1990. while ($entry = readdir($handle)) {
  1991. if (substr($entry, 0, 1) != '.') {
  1992. $fullsrc = $pathFrom.SYS_PATH_SEP.$entry;
  1993. $fulldst = $pathTo.SYS_PATH_SEP.$entry;
  1994. if (is_dir($fullsrc)) {
  1995. $operationsPublish .= '&gt; avvio la copia per "'.$entry.':<br />';
  1996. hardFlush(&$operationsPublish);
  1997. if (!is_dir($fulldst)) mkdir($fulldst, CHMOD);
  1998. @chmod($fulldst, CHMOD);
  1999. $prosecute = publish_recurseMedia($fullsrc, $fulldst, &$operationsPublish);
  2000. $operationsPublish .= '... ok<br />';
  2001. hardFlush(&$operationsPublish);
  2002. } else {
  2003. $srcx = filemtime($fullsrc);
  2004. $tgtx = false || @filemtime($fulldst);
  2005. if ($srcx > $tgtx) {
  2006. $operationsPublish .= '&gt; copio "'.basename($pathFrom).SYS_PATH_SEP.$entry.'<br />';
  2007. hardFlush(&$operationsPublish);
  2008. copy($fullsrc, $fulldst);
  2009. @chmod($fulldst, CHMOD);
  2010. $prosecute = true;
  2011. };
  2012. };
  2013. };
  2014. };
  2015. };
  2016. return TRUE && $prosecute;
  2017. };
  2018. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2019. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2020. function publish_SendToXDB ($exist, $collName, $packName, $partName, &$operationsPublish) {
  2021. global $EXTENSION_PACKAGE;
  2022. // INIT
  2023. $toPublish = array();
  2024. // PREPARA FOLDERS
  2025. $component = $collName;
  2026. if ($packName != '') {
  2027. $component .= SYS_PATH_SEP.$packName;
  2028. };
  2029. $operationsPublish .= '&gt; avvio la preparazione dei dati per "'.$component.':<br />';
  2030. hardFlush(&$operationsPublish);
  2031. $prosecute = TRUE;
  2032. if (!is_dir(DCTL_PUBLISH)) {
  2033. if (mkdir(DCTL_PUBLISH, CHMOD)) {
  2034. $operationsPublish .= '&gt; creo cartella '.DCTL_PUBLISH.'...<br />';
  2035. } else {
  2036. $operationsPublish .= '<span class="error">impossibile creare la cartella "'.DCTL_PUBLISH.'"!</span><br />';
  2037. $prosecute = FALSE;
  2038. };
  2039. };
  2040. @chmod(DCTL_PUBLISH, CHMOD);
  2041. $operationsPublish .= '&gt; avvio la preparazione dei file in "'.DCTL_PUBLISH.'":<br />';
  2042. hardFlush(&$operationsPublish);
  2043. if ($prosecute) {
  2044. // COPIA I DTD
  2045. dircopy(DCTL_SETTINGS_DTD, DCTL_PUBLISH);
  2046. $operationsPublish .= '&#160;&#160;- copio "'.DCTL_DTD.'"...<br />';
  2047. hardFlush(&$operationsPublish);
  2048. // COPIA GLI ADD-ONS
  2049. dircopy(DCTL_SETTINGS_ADDONS, DCTL_PUBLISH);
  2050. $operationsPublish .= '&#160;&#160;- copio "'.DCTL_ADDONS.'"...<br />';
  2051. hardFlush(&$operationsPublish);
  2052. // AGGIORNA IL CATALOGO.XML
  2053. $operationsPublish .= '&#160;&#160;- verifico il catalogo dei "'.DCTL_DTD.'":<br />';
  2054. hardFlush(&$operationsPublish);
  2055. $dtd_catalog = XMLDB_CATALOG;
  2056. try {
  2057. if (isset($xml_dom)) unset($xml_dom);
  2058. $xml_dom = new DOMDocument('1.0', 'UTF-8');
  2059. $xml_dom->preserveWhiteSpace = false;
  2060. forceUTF8($dtd_catalog);
  2061. $xml_dom->load($dtd_catalog, DCTL_XML_LOADER);
  2062. } catch (Exception $e) {
  2063. $operationsPublish .= '<span class="error">impossibile caricare XML "'.$entry.'"... {'.$e.'}</span><br />';
  2064. $prosecute = FALSE;
  2065. };
  2066. if ($prosecute) {
  2067. $upd = FALSE;
  2068. $dtds_needed = array();
  2069. $handle = opendir(DCTL_SETTINGS_DTD);
  2070. while ($entry = readdir($handle)) {
  2071. if (substr($entry, 0, 1) != '.') {
  2072. $srcx = filemtime(DCTL_SETTINGS_DTD.$entry);
  2073. $tgtx = false || @filemtime(XMLDB_ENTITIES.SYS_PATH_SEP.$entry);
  2074. if ($srcx > $tgtx) {
  2075. $upd = TRUE;
  2076. };
  2077. };
  2078. };
  2079. dircopy(DCTL_SETTINGS_DTD, XMLDB_ENTITIES, &$dtds_needed);
  2080. $operationsPublish .= '&#160;&#160;- copio da "'.DCTL_SETTINGS_DTD.'" a "'.XMLDB_ENTITIES.'"...<br />';
  2081. hardFlush(&$operationsPublish);
  2082. $dtds_present = $xml_dom->getElementsByTagName('system');
  2083. foreach($dtds_present as $dtd_present) {
  2084. $dtd_chk = $dtd_present->getAttribute('systemId');
  2085. $dtd_key = array_search($dtd_chk, $dtds_needed);
  2086. if ($dtd_key !== FALSE) {
  2087. $dtds_needed[$dtd_key] = '';
  2088. };
  2089. };
  2090. foreach($dtds_needed as $dtd_needed) {
  2091. if ($dtd_needed != '') {
  2092. $node = $xml_dom->createElement('system');
  2093. $dtd_root = $xml_dom->getElementsByTagName('catalog')->item(0);
  2094. $newnode = $dtd_root->appendChild($node);
  2095. $newnode->setAttribute('systemId', $dtd_needed);
  2096. $newnode->setAttribute('uri', 'entities'.SYS_PATH_SEP.$dtd_needed);
  2097. $operationsPublish .= '&gt; aggiungo '.$dtd_needed.'...<br />';
  2098. hardFlush(&$operationsPublish);
  2099. $upd = TRUE;
  2100. };
  2101. };
  2102. if ($upd == TRUE) {
  2103. $xml_dom->save($dtd_catalog);
  2104. $operationsPublish .= '<span class="error">Aggiornamento non eseguito per modifiche necessarie al database.</span><br />';
  2105. $operationsPublish .= '<span class="error">IMPORTANTE: riavviare exist per proseguire correttamente (aggiornato "catalog.xml")!</span><br />';
  2106. $prosecute = FALSE;
  2107. };
  2108. if ($prosecute) {
  2109. // PREPARA XML #1
  2110. $xsl_path = DCTL_COMMODORO_XSLT.'tei_publisher_1.xsl';
  2111. if (!is_file($xsl_path)) {
  2112. $operationsPublish .= '<span class="error">impossibile trovare XSLT "'.$xsl_path.'"!</span><br />';
  2113. $prosecute = FALSE;
  2114. } else {
  2115. try {
  2116. if (isset($xsl_dom)) unset($xsl_dom);
  2117. $xsl_dom = new DOMDocument('1.0', 'UTF-8');
  2118. $xsl_dom->preserveWhiteSpace = false;
  2119. forceUTF8($xsl_path);
  2120. $xsl_dom->load($xsl_path, DCTL_XML_LOADER);
  2121. } catch (Exception $e) {
  2122. $operationsPublish .= '<span class="error">impossibile caricare XSLT "'.$xsl_path.'"... {'.$e.'}</span><br />';
  2123. $prosecute = FALSE;
  2124. };
  2125. if ($prosecute) {
  2126. $operationsPublish .= '&gt; carico XSLT "'.$xsl_path.'"...<br />';
  2127. hardFlush(&$operationsPublish);
  2128. try {
  2129. if (isset($xsl_proc)) unset($xsl_proc);
  2130. $xsl_proc = new XSLTProcessor();
  2131. $xsl_proc->registerPHPFunctions();
  2132. $xsl_proc->importStyleSheet($xsl_dom); // attach the xsl rules
  2133. } catch (Exception $e) {
  2134. $operationsPublish .= '<span class="error">impossibile inizializzare il processore XSL... {'.$e.'}</span><br />';
  2135. $prosecute = FALSE;
  2136. };
  2137. if ($prosecute) {
  2138. $operationsPublish .= '&gt; trasformo i file XML (#1):<br />';
  2139. $prosecute = publish_recurseContents(DCTL_PROJECT_PATH.$collName, $collName, $packName, $xsl_proc, &$operationsPublish, &$toPublish);
  2140. };
  2141. if ($prosecute) {
  2142. // PREPARA XML #2
  2143. $xsl_path = DCTL_COMMODORO_XSLT.'tei_publisher_2.xsl';
  2144. if (!is_file($xsl_path)) {
  2145. $operationsPublish .= '<span class="error">impossibile trovare XSLT "'.$xsl_path.'"!</span><br />';
  2146. $prosecute = FALSE;
  2147. } else {
  2148. try {
  2149. if (isset($xsl_dom)) unset($xsl_dom);
  2150. $xsl_dom = new DOMDocument('1.0', 'UTF-8');
  2151. $xsl_dom->preserveWhiteSpace = false;
  2152. forceUTF8($xsl_path);
  2153. $xsl_dom->load($xsl_path, DCTL_XML_LOADER);
  2154. } catch (Exception $e) {
  2155. $operationsPublish .= '<span class="error">impossibile caricare XSLT "'.$xsl_path.'"... {'.$e.'}</span><br />';
  2156. $prosecute = FALSE;
  2157. };
  2158. if ($prosecute) {
  2159. $operationsPublish .= '&gt; carico XSLT "'.$xsl_path.'"...<br />';
  2160. hardFlush(&$operationsPublish);
  2161. try {
  2162. if (isset($xsl_proc)) unset($xsl_proc);
  2163. $xsl_proc = new XSLTProcessor();
  2164. $xsl_proc->registerPHPFunctions();
  2165. $xsl_proc->importStyleSheet($xsl_dom); // attach the xsl rules
  2166. } catch (Exception $e) {
  2167. $operationsPublish .= '<span class="error">impossibile inizializzare il processore XSL... {'.$e.'}</span><br />';
  2168. $prosecute = FALSE;
  2169. };
  2170. if ($prosecute) {
  2171. $operationsPublish .= '&gt; trasformo i file XML :: ID/NUM (#2):<br />';
  2172. hardFlush(&$operationsPublish);
  2173. foreach($toPublish as $fullsrc) {
  2174. $prosecute = true;
  2175. $fulldst = $fullsrc;
  2176. $entry = basename($fulldst);
  2177. if (in_array(substr($entry, -8, 4), $EXTENSION_PACKAGE) !== FALSE) {
  2178. $operationsPublish .= '&#160;- trasformazione XSLT per XML "'.$entry.'":';
  2179. try {
  2180. if (isset($xml_dom)) unset($xml_dom);
  2181. $xml_dom = new DOMDocument('1.0', 'UTF-8');
  2182. $xsl_dom->preserveWhiteSpace = false;
  2183. forceUTF8($fullsrc);
  2184. $xml_dom->load($fullsrc, DCTL_XML_LOADER);
  2185. } catch (Exception $e) {
  2186. $operationsPublish .= '<span class="error">impossibile caricare XML "'.$entry.'"... {'.$e.'}</span><br />';
  2187. $prosecute = FALSE;
  2188. };
  2189. if ($prosecute) {
  2190. $operationsPublish .= '&#160;aggiorno...';
  2191. try {
  2192. $text = $xsl_proc->transformToXML($xml_dom);
  2193. } catch (Exception $e) {
  2194. $operationsPublish .= '<span class="error">impossibile trasformare XML "'.$entry.'"... {'.$e.'}</span><br />';
  2195. $prosecute = FALSE;
  2196. };
  2197. if ($prosecute) {
  2198. $operationsPublish .= '&#160;scrivo XML...';
  2199. $text = str_ireplace('xmlns=""','', $text);
  2200. try {
  2201. $fd = fopen ($fulldst, "wb");
  2202. $out = fwrite ($fd, forceUTF8($text));
  2203. fclose ($fd);
  2204. @chmod($fulldst, CHMOD);
  2205. $operationsPublish .= '&#160;ok<br/>';
  2206. } catch (Exception $e) {
  2207. $operationsPublish .= '<span class="error">impossibile riscrivere XML "'.$entry.'"... {'.$e.'}</span><br />';
  2208. $prosecute = FALSE;
  2209. };
  2210. hardFlush(&$operationsPublish);
  2211. };
  2212. };
  2213. };
  2214. };
  2215. };
  2216. if ($prosecute) {
  2217. // PREPARA XML #3
  2218. // 3) carico i file XML e li trasformo
  2219. $xsl_path = DCTL_COMMODORO_XSLT.'tei_publisher_3.xsl';
  2220. if (!is_file($xsl_path)) {
  2221. $operationsPublish .= '<span class="error">impossibile trovare XSLT "'.$xsl_path.'"!</span><br />';
  2222. $prosecute = FALSE;
  2223. };
  2224. if ($prosecute) {
  2225. try {
  2226. if (isset($xsl_dom)) unset($xsl_dom);
  2227. $xsl_dom = new DOMDocument('1.0', 'UTF-8');
  2228. $xsl_dom->preserveWhiteSpace = false;
  2229. forceUTF8($xsl_path);
  2230. $xsl_dom->load($xsl_path, DCTL_XML_LOADER);
  2231. } catch (Exception $e) {
  2232. $operationsPublish .= '<span class="error">impossibile caricare XSLT "'.$xsl_path.'"... {'.$e.'}</span><br />';
  2233. $prosecute = FALSE;
  2234. };
  2235. if ($prosecute) {
  2236. $operationsPublish .= '&gt; carico XSLT "'.$xsl_path.'"...<br />';
  2237. hardFlush(&$operationsPublish);
  2238. try {
  2239. if (isset($xsl_proc)) unset($xsl_proc);
  2240. $xsl_proc = new XSLTProcessor();
  2241. $xsl_proc->registerPHPFunctions();
  2242. $xsl_proc->importStyleSheet($xsl_dom); // attach the xsl rules
  2243. } catch (Exception $e) {
  2244. $operationsPublish .= '<span class="error">impossibile inizializzare il processore XSL... {'.$e.'}</span><br />';
  2245. $prosecute = FALSE;
  2246. };
  2247. if ($prosecute) {
  2248. $operationsPublish .= '&gt; trasformo i file XML :: LABEL/NAME/TOPIC (#3):<br />';
  2249. hardFlush(&$operationsPublish);
  2250. global $mysql_dbName;
  2251. global $mysql_dbIconclass;
  2252. try {
  2253. $mysql_dbName = dctl_sql_connect(DCTL_DB_NAME);
  2254. } catch (Exception $e) {
  2255. die('<span class="wctl_error">[DB] ' . $e . '</span>');
  2256. };
  2257. try {
  2258. $mysql_dbIconclass = dctl_sql_connect(DCTL_DB_ICONCLASS);
  2259. } catch (Exception $e) {
  2260. die('<span class="wctl_error">[DB] ' . $e . '</span>');
  2261. };
  2262. foreach($toPublish as $fullsrc) {
  2263. $prosecute = true;
  2264. $fulldst = $fullsrc;
  2265. $entry = basename($fulldst);
  2266. if (in_array(substr($entry, -8, 4), $EXTENSION_PACKAGE) !== FALSE) {
  2267. $operationsPublish .= '&#160;- trasformazione XSLT per XML "'.$entry.'":';
  2268. try {
  2269. if (isset($xml_dom)) unset($xml_dom);
  2270. $xml_dom = new DOMDocument('1.0', 'UTF-8');
  2271. $xml_dom->preserveWhiteSpace = false;
  2272. forceUTF8($fullsrc);
  2273. $xml_dom->load($fullsrc, DCTL_XML_LOADER);
  2274. } catch (Exception $e) {
  2275. $operationsPublish .= '<span class="error">impossibile caricare XML "'.$entry.'"... {'.$e.'}</span><br />';
  2276. $prosecute = FALSE;
  2277. };
  2278. if ($prosecute) {
  2279. $operationsPublish .= '&#160;aggiorno...';
  2280. if ($mysql_dbName && $mysql_dbIconclass) {
  2281. try {
  2282. $text = $xsl_proc->transformToXML($xml_dom);
  2283. } catch (Exception $e) {
  2284. $operationsPublish .= '<span class="error">impossibile trasformare XML "'.$entry.'"... {'.$e.'}</span><br />';
  2285. $prosecute = FALSE;
  2286. };
  2287. if ($prosecute) {
  2288. $operationsPublish .= '&#160;scrivo XML...';
  2289. $text = str_ireplace('xmlns=""','', $text);
  2290. try {
  2291. $fd = fopen ($fulldst, "wb");
  2292. $out = fwrite ($fd, forceUTF8($text, $fulldst));
  2293. fclose ($fd);
  2294. @chmod($fulldst, CHMOD);
  2295. $operationsPublish .= 'ok<br/>';
  2296. } catch (Exception $e) {
  2297. $operationsPublish .= '<span class="error">impossibile riscrivere XML "'.$entry.'"... {'.$e.'}</span><br />';
  2298. $prosecute = FALSE;
  2299. };
  2300. hardFlush(&$operationsPublish);
  2301. };
  2302. } else {
  2303. $operationsPublish .= '<span class="error">impossibile connettersi a MySQL...</span><br />';
  2304. $prosecute = FALSE;
  2305. };
  2306. };
  2307. };
  2308. };
  2309. mysql_close($mysql_dbName);
  2310. mysql_close($mysql_dbIconclass);
  2311. if ($prosecute) {
  2312. // PREPARA XMLDB
  2313. $operationsPublish .= '&gt; connessione al database "exist":<br />';
  2314. hardFlush(&$operationsPublish);
  2315. if (!$exist) {
  2316. $operationsPublish .= '<span class="error">impossibile connettersi al database "exist"... {'.$e.'}</span><br />';
  2317. $prosecute = FALSE;
  2318. };
  2319. if ($prosecute) {
  2320. $baseDB = XMLDB_PATH_BASE;
  2321. $result = ($exist->createCollection($baseDB) != FALSE) or dump($exist->getError());
  2322. if (!$result) {
  2323. $operationsPublish .= '<span class="error">impossibile creare la Collection base "'.$baseDB.'"!</span><br />';
  2324. $prosecute = FALSE;
  2325. };
  2326. if ($prosecute) {
  2327. // 1) creo la collezione in exist
  2328. $operationsPublish .= '&#160;&#160;- aggiorno la Collection "'.$collName.'":<br />';
  2329. hardFlush(&$operationsPublish);
  2330. if ($packName == '') {
  2331. $exist->removeCollection($baseDB.$collName);
  2332. $operationsPublish .= '&#160;&#160;- ripulisco la Collection "'.$collName.'"...<br />';
  2333. };
  2334. $result = ($exist->createCollection($baseDB.$collName) != FALSE) or dump($exist->getError());
  2335. if (!$result) {
  2336. $operationsPublish .= '<span class="error">impossibile creare la Collection "'.$collName.'"!</span><br />';
  2337. $prosecute = FALSE;
  2338. };
  2339. $operationsPublish .= '&gt; pubblico i dati nel database...<br />';
  2340. hardFlush(&$operationsPublish);
  2341. foreach($toPublish as $fullsrc) {
  2342. $prosecute = true;
  2343. $fulldst = $fullsrc;
  2344. $entry = basename($fulldst);
  2345. // 3) pubblico nella collezione di exist
  2346. $operationsPublish .= '&#160;&#160;- pubblico "'.$entry.'"...';
  2347. $pathTo = $baseDB.$collName.DB_PATH_SEP.$entry;
  2348. $result = ($exist->uploadResource($pathTo, $fulldst) !== FALSE) or dump($exist->getError());
  2349. if (!$result) {
  2350. $operationsPublish .= '<span class="error">impossibile pubblicare XML "'.$entry.'"!</span><br />';
  2351. $prosecute = FALSE;
  2352. } else {
  2353. $operationsPublish .= '&#160;ok<br />';
  2354. $prosecute = TRUE;
  2355. };
  2356. hardFlush(&$operationsPublish);
  2357. };
  2358. if ($prosecute) {
  2359. $fullsrc = DCTL_PROJECT_PATH.$collName.SYS_PATH_SEP.DCTL_MEDIA;
  2360. if (true) {
  2361. $prosecute = publish_recurseMedia($fullsrc, DCTL_PUBLISH_MEDIA, &$operationsPublish);
  2362. } else {
  2363. if (! COPY_MEDIA) {
  2364. $operationsPublish .= '<br /><span class="error">RI-ABILITA COPIA DEI MEDIA...';
  2365. } else {
  2366. // COPIA MEDIA
  2367. $operationsPublish .= '&#160;&#160;- copio "'.$fullsrc.'"...<br />';
  2368. hardFlush(&$operationsPublish);
  2369. dircopy($fullsrc, DCTL_PUBLISH_MEDIA);
  2370. };
  2371. };
  2372. $operationsPublish .= '<br /><span class="ok">Pubblicazione per "'.$collName;
  2373. if ($packName != '') {
  2374. $operationsPublish .= SYS_PATH_SEP.$packName;
  2375. };
  2376. $operationsPublish .= '" effettuata con successo.</span><br /><br />';
  2377. } else {
  2378. $operationsPublish .= '<br /><span class="error">Errori nella pubblicazione per "'.$component.'"!</span><br /><br />';
  2379. };
  2380. hardFlush(&$operationsPublish);
  2381. };
  2382. };
  2383. };
  2384. };
  2385. };
  2386. };
  2387. };
  2388. };
  2389. };
  2390. };
  2391. };
  2392. };
  2393. };
  2394. };
  2395. };
  2396. return TRUE && $prosecute;
  2397. };
  2398. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2399. function publish_RemoveFromXDB ($exist, $collName, $packName, $partName, &$operationsPublish) {
  2400. $toPublish = array();
  2401. $component = $collName;
  2402. if ($packName != '') {
  2403. $component .= SYS_PATH_SEP.$packName;
  2404. };
  2405. $operationsPublish .= '(*) &gt; avvio la de-pubblicazione sul web per "'.$component.'":<br />';
  2406. hardFlush(&$operationsPublish);
  2407. $prosecute = $collName != '';
  2408. if ($prosecute) {
  2409. // DE-PUBBLICA SU XMLDB
  2410. $operationsPublish .= '&gt; connessione al database "exist":<br />';
  2411. hardFlush(&$operationsPublish);
  2412. $baseDB = XMLDB_PATH_BASE;
  2413. if ($packName == '') {
  2414. if (@$exist->removeCollection($baseDB.$collName)) {
  2415. $operationsPublish .= '&gt; de-pubblico la Collection "'.$collName.'"...<br />';
  2416. } else {
  2417. $operationsPublish .= '<span class="error">impossibile de-pubblicare la Collection "'.$collName.'"!</span><br />';
  2418. };
  2419. } else {
  2420. if ($exist->removeDocument($baseDB.$collName.SYS_PATH_SEP.$packName.'.xml')) {
  2421. $operationsPublish .= '&gt; de-pubblico il Package "'.$packName.'" in "'.$collName.'"...<br />';
  2422. } else {
  2423. $operationsPublish .= '<span class="error">impossibile de-pubblicare il Package "'.$packName.'" in "'.$collName.'"!</span><br />';
  2424. };
  2425. };
  2426. };
  2427. hardFlush(&$operationsPublish);
  2428. return TRUE && $prosecute;
  2429. };
  2430. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2431. function simplexml2ISOarray ($simplexml,$attribsAsElements=0) {
  2432. if (get_class($simplexml) == 'SimpleXMLElement') {
  2433. $attributes = $simplexml->attributes();
  2434. foreach($attributes as $k=>$v) {
  2435. if ($v) $a[$k] = (string) $v;
  2436. };
  2437. $x = $simplexml;
  2438. $simplexml = get_object_vars($simplexml);
  2439. };
  2440. if (is_array($simplexml)) {
  2441. if (count($simplexml) == 0) return (string) $x; // for CDATA
  2442. foreach($simplexml as $key=>$value) {
  2443. $r[$key] = simplexml2ISOarray($value,$attribsAsElements);
  2444. if (!is_array($r[$key])) $r[$key] = utf8_decode($r[$key]);
  2445. };
  2446. if (isset($a)) {
  2447. if($attribsAsElements) {
  2448. $r = array_merge($a,$r);
  2449. } else {
  2450. $r['@'] = $a; // Attributes
  2451. };
  2452. };
  2453. return $r;
  2454. };
  2455. return (string) $simplexml;
  2456. };
  2457. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2458. function doThumbnail() {
  2459. // define the base image dir
  2460. $base_img_dir = "./";
  2461. // $QUERY_STRING =
  2462. // f(3c9b5fa6bc0fa) img_file
  2463. // w(123|15%) width of output
  2464. // h(123|10%) height of output
  2465. // x(123) max width of output
  2466. // y(123) max height of output
  2467. // t(jpg|png) type of output
  2468. // q(100) quality of jpeg
  2469. // find tags
  2470. preg_match_all("/\+*(([a-z])\(([^\)]+)\))\+*/", $QUERY_STRING,
  2471. $matches, PREG_SET_ORDER);
  2472. // empty array and set regular expressions for the check
  2473. $tags = array();
  2474. $check = array( "f" => "[0-9a-zA-Z]{13}",
  2475. "w" => "[0-9]+%?",
  2476. "h" => "[0-9]+%?",
  2477. "x" => "[0-9]+",
  2478. "y" => "[0-9]+",
  2479. "t" => "jpg|png",
  2480. "q" => "1?[0-9]{1,2}" );
  2481. // check tags and save correct values in array
  2482. for ($i=0; $i<count($matches); $i++) {
  2483. if (isset($check[$matches[$i][2]])) {
  2484. if (preg_match('/^('.$check[$matches[$i][2]].')$/',
  2485. $matches[$i][3])) {
  2486. $tags[$matches[$i][2]] = $matches[$i][3];
  2487. }
  2488. }
  2489. }
  2490. function notfound() {
  2491. header("HTTP/1.0 404 Not Found");
  2492. exit;
  2493. }
  2494. // check that filename is given
  2495. if (!isset($tags["f"])) {
  2496. notfound();
  2497. }
  2498. // check if file exists
  2499. if (!file_exists($base_img_dir.$tags["f"])) {
  2500. notfound();
  2501. }
  2502. // retrieve file info
  2503. $imginfo = getimagesize($base_img_dir.$tags["f"]);
  2504. // load image
  2505. switch ($imginfo[2]) {
  2506. case 2: // jpg
  2507. $img_in = imagecreatefromjpeg($base_img_dir.$tags["f"]) or notfound();
  2508. if (!isset($tags["t"])) {
  2509. $tags["t"] = "jpg";
  2510. }
  2511. break;
  2512. case 3: // png
  2513. $img_in = imagecreatefrompng($base_img_dir.$tags["f"]) or notfound();
  2514. if (!isset($tags["t"])) {
  2515. $tags["t"] = "png";
  2516. }
  2517. break;
  2518. default:
  2519. notfound();
  2520. }
  2521. // check for maximum width and height
  2522. if (isset($tags["x"])) {
  2523. if ($tags["x"] < imagesx($img_in)) {
  2524. $tags["w"] = $tags["x"];
  2525. }
  2526. }
  2527. if (isset($tags["y"])) {
  2528. if ($tags["y"] < imagesy($img_in)) {
  2529. $tags["h"] = $tags["y"];
  2530. }
  2531. }
  2532. // check for need to resize
  2533. if (isset($tags["h"]) or isset($tags["w"])) {
  2534. // convert relative to absolute
  2535. if (isset($tags["w"])) {
  2536. if (strstr($tags["w"], "%")) {
  2537. $tags["w"] = (intval(substr($tags["w"], 0, -1)) / 100) *
  2538. $imginfo[0];
  2539. }
  2540. }
  2541. if (isset($tags["h"])) {
  2542. if (strstr($tags["h"], "%")) {
  2543. $tags["h"] = (intval(substr($tags["h"], 0, -1)) / 100) *
  2544. $imginfo[1];
  2545. }
  2546. }
  2547. // resize
  2548. if (isset($tags["w"]) and isset($tags["h"])) {
  2549. $out_w = $tags["w"];
  2550. $out_h = $tags["h"];
  2551. } elseif (isset($tags["w"]) and !isset($tags["h"])) {
  2552. $out_w = $tags["w"];
  2553. $out_h = $imginfo[1] * ($tags["w"] / $imginfo[0]);
  2554. } elseif (!isset($tags["w"]) and isset($tags["h"])) {
  2555. $out_w = $imginfo[0] * ($tags["h"] / $imginfo[1]);
  2556. $out_h = $tags["h"];
  2557. } else {
  2558. $out_w = $tags["w"];
  2559. $out_h = $tags["h"];
  2560. }
  2561. // new image in $img_out
  2562. $img_out = imagecreate($out_w, $out_h);
  2563. imagecopyresized($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out),
  2564. imagesy($img_out), imagesx($img_in), imagesy($img_in));
  2565. } else {
  2566. // no resize needed
  2567. $img_out = $img_in;
  2568. }
  2569. // check for a given jpeg-quality, otherwise set to default
  2570. if (!isset($tags["q"])) {
  2571. $tags["q"] = 75;
  2572. }
  2573. // returning the image
  2574. switch ($tags["t"]) {
  2575. case "jpg":
  2576. header("Content-type: image/jpeg");
  2577. imagejpeg($img_out, "", $tags["q"]);
  2578. exit;
  2579. case "png":
  2580. header("Content-type: image/png");
  2581. imagepng($img_out);
  2582. exit;
  2583. default:
  2584. notfound();
  2585. }
  2586. };
  2587. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2588. function get_dbName ($theKey, $theAttribute) {
  2589. global $mysql_dbName;
  2590. $theAttribute = str_ireplace(' ', '', $theAttribute);
  2591. $text = '';
  2592. if ($theKey != '') {
  2593. $query = 'SELECT * FROM tNAME WHERE tNAME.id="'.$theKey.'"';
  2594. $result = mysql_query($query, $mysql_dbName) or die ("Error in query: $query. ".mysql_error());
  2595. if (mysql_num_rows($result) == 1) {
  2596. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  2597. switch ($theAttribute) {
  2598. case 'name':
  2599. $text = $row['name'];
  2600. break;
  2601. case 'type':
  2602. $text = $row['type'];
  2603. break;
  2604. case 'subtype':
  2605. $text = $row['subtype'];
  2606. break;
  2607. default:
  2608. $text = '???';
  2609. break;
  2610. };
  2611. };
  2612. };
  2613. return forceUTF8(strval(ucfirst(trim($text))), '', false);
  2614. };
  2615. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2616. function get_dbIconclass ($theKey, $theAttribute) {
  2617. global $mysql_dbIconclass;
  2618. $theAttribute = str_ireplace(' ', '', $theAttribute);
  2619. $text = '';
  2620. if ($theKey != '') {
  2621. $query = 'SELECT * FROM tNAME WHERE tNAME.id="'.$theKey.'"';
  2622. $result = mysql_query($query, $mysql_dbIconclass) or die ("Error in query: $query. ".mysql_error());
  2623. if (mysql_num_rows($result) == 1) {
  2624. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  2625. switch ($theAttribute) {
  2626. case 'name':
  2627. $text = $row['name'];
  2628. break;
  2629. case 'iconclass':
  2630. $text = $row['iconclass'];
  2631. break;
  2632. default:
  2633. $text = '???';
  2634. break;
  2635. };
  2636. };
  2637. };
  2638. return forceUTF8(strval(ucfirst(trim($text))), '', false);
  2639. };
  2640. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2641. /* NO ?> IN FILE .INC */
  2642. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2643. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2644. // * UNUSED BUT USEFUL...
  2645. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2646. function ajax_loadFullTree ($upToLevel=0, $collection_id='', $media_id='', $package_id='', $part_id='') {
  2647. $resultText = '';
  2648. // BEGIN
  2649. $basePath = DCTL_PROJECT_PATH;
  2650. $collectionPath = $basePath.$collection_id;
  2651. if (($collection_id == '') || ($upToLevel==1)) {
  2652. // ALL COLLECTIONS
  2653. $resultText .= '<ul>';
  2654. getCollectionList($basePath, &$collectionList);
  2655. foreach ($collectionList['path'] as $key=>$fPath) {
  2656. getCollectionRecord($fPath, &$collectionRecord);
  2657. $selected = $collection_id == $collectionRecord['collection_id'];
  2658. $resultText .= '<li'.($selected ? ' class="open"' : '').'>';
  2659. $resultText .= '<span class="text"><span class="collection '.($selected?' selected':'').'">'.$collectionRecord['collection_full'].'</span></span>';
  2660. if ($selected) {
  2661. $resultText .= ajax_loadTree(2, $collection_id, $media_id, $package_id, $part_id, $what);
  2662. } else {
  2663. $resultText .= '<ul'.($selected ? '' : ' class="ajax"').'>';
  2664. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadFullTree&amp;collection_id='.$collectionRecord['collection_id'].'}</li>';
  2665. $resultText .= '</ul>';
  2666. };
  2667. $resultText .= '</li>';
  2668. };
  2669. $resultText .= '<li class="add"><span class="text">aggiungi Collection...</span></li>';
  2670. $resultText .= '</ul>';
  2671. } else {
  2672. // ONE COLLECTION
  2673. if ((($package_id == '') && ($media_id == '')) || ($upToLevel==2)) {
  2674. $resultText .= '<ul>';
  2675. $resultText .= '<li class="edit"><span class="text">edit Collection...</span></li>';
  2676. $resultText .= '<li class="publish"><span class="text">Pubblicazione Web</span>';
  2677. $resultText .= '<a href="#" title="Pubblica" class="publish"><span class="hidden">Pubblica</span></a>';
  2678. $resultText .= '<a href="#" title="Ritira" class="unpublish"><span class="hidden">Ritira</span></a>';
  2679. $resultText .= '</li>';
  2680. // LOAD PACKAGES
  2681. $resultText .= '<li'.($package_id!='' ? ' class="open"' : '').'>';
  2682. $resultText .= '<span class="text">Gestione Package</span>';
  2683. if ($package_id!='') {
  2684. $resultText .=ajax_loadTree(3, $collection_id, '', $package_id, $part_id, $what);
  2685. } else {
  2686. $resultText .= '<ul'.($package_id=='' ? ' class="ajax"' : '').'>';
  2687. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadFullTree&amp;collection_id='.$collection_id.'&amp;package_id=*}</li>';
  2688. $resultText .= '</ul>';
  2689. };
  2690. $resultText .= '</li>';
  2691. // LOAD MEDIA
  2692. $resultText .= '<li'.($media_id!='' ? ' class="open"' : '').'>';
  2693. $resultText .= '<span class="text">Gestione Media</span>';
  2694. if ($media_id!='') {
  2695. $resultText .= ajax_loadTree(3, $collection_id, $media_id, '', $part_id, $what);
  2696. } else {
  2697. $resultText .= '<ul'.($media_id=='' ? ' class="ajax"' : '').'>';
  2698. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadFullTree&amp;collection_id='.$collection_id.'&amp;media_id=*}</li>';
  2699. $resultText .= '</ul>';
  2700. };
  2701. $resultText .= '</li>';
  2702. $resultText .= '</ul>';
  2703. } else {
  2704. if ($package_id != '') {
  2705. if (($package_id == '*') || ($upToLevel==3)) {
  2706. // ALL PACKAGES
  2707. $basePath = $collectionPath;
  2708. $packagePath = $basePath.$package_id;
  2709. $resultText .= '<ul>';
  2710. getPackageList($basePath, &$packageList);
  2711. foreach ($packageList['path'] as $key=>$fPath) {
  2712. getPackageRecord($fPath, &$packageRecord);
  2713. $selected = $package_id == $packageRecord['package_id'];
  2714. $resultText .= '<li'.($selected ? ' class="open"' : '').'>';
  2715. $resultText .= '<span class="text"><span class="package'.($selected?' selected':'').'">'.$packageRecord['package_full'].'</span></span>';
  2716. if ($selected) {
  2717. $resultText .= ajax_loadTree(4, $collection_id, '', $package_id, $part_id, $what);
  2718. } else {
  2719. $resultText .= '<ul'.($selected ? '' : ' class="ajax"').'>';
  2720. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadFullTree&amp;collection_id='.$collection_id.'&amp;package_id='.$packageRecord['package_id'].'}</li>';
  2721. $resultText .= '</ul>';
  2722. };
  2723. $resultText .= '</li>';
  2724. };
  2725. $resultText .= '<li class="add"><span class="text">aggiungi Package...</span></li>';
  2726. $resultText .= '</ul>';
  2727. } else {
  2728. if (($part_id == '') || ($upToLevel==4)) {
  2729. $resultText .= '<ul>';
  2730. $resultText .= '<li class="edit"><span class="text">edit Package...</span></li>';
  2731. $resultText .= '<li class="publish"><span class="text">Pubblicazione Web</span>';
  2732. $resultText .= '<a href="#" title="Pubblica" class="publish"><span class="hidden">Pubblica</span></a>';
  2733. $resultText .= '<a href="#" title="Ritira" class="unpublish"><span class="hidden">Ritira</span></a>';
  2734. $resultText .= '</li>';
  2735. // LOAD PARTS
  2736. $resultText .= '<li'.($part_id!='' ? ' class="open"' : '').'>';
  2737. $resultText .= '<span class="text">Gestione Part</span>';
  2738. if ($part_id!='') {
  2739. $resultText .= ajax_loadTree(5, $collection_id, '', $package_id, $part_id, $what);
  2740. } else {
  2741. $resultText .= '<ul'.($part_id=='' ? ' class="ajax"' : '').'>';
  2742. $resultText .= '<li>{url:indexAjax.php?action=ajax_loadFullTree&amp;collection_id='.$collection_id.'&amp;package_id='.$package_id.'&amp;part_id=*}</li>';
  2743. $resultText .= '</ul>';
  2744. };
  2745. $resultText .= '</li>';
  2746. $resultText .= '</ul>';
  2747. } else {
  2748. // ALL PARTS
  2749. $basePath = $collectionPath.$package_id.SYS_PATH_SEP;
  2750. $partPath = $basePath.$part_id;
  2751. $resultText .= '<ul>';
  2752. getPartList($basePath, &$partList);
  2753. foreach ($partList['path'] as $key=>$fPath) {
  2754. getPartRecord($fPath, &$partRecord);
  2755. $selected = $part_id == $partRecord['part_id'];
  2756. $resultText .= '<li'.($selected?' class="open"':'').'>';
  2757. $resultText .= '<span class="text"><span class="part'.($selected?' selected':'').'">'.cleanWebString($partRecord['part_short'].' - '.$partRecord['part_work'], FIELD_STRING_LENGTH).SYS_DBL_SPACE. '</span></span>';
  2758. $resultText .= '<a href="#" title="Scarica" class="dnload"><span class="hidden">Scarica</span></a>';
  2759. $resultText .= '<a href="#" title="Ricarica" class="upload"><span class="hidden">Ricarica</span></a>';
  2760. $resultText .= '</li>';
  2761. };
  2762. $resultText .= '<li class="add"><span class="text">aggiungi Part...</span></li>';
  2763. $resultText .= '</ul>';
  2764. };
  2765. };
  2766. };
  2767. if ($media_id!='') {
  2768. // ALL MEDIA
  2769. $basePath = $collectionPath.DCTL_MEDIA_BIG;
  2770. $mediaPath = $basePath.$media_id;
  2771. $resultText .= '<ul>';
  2772. getMediaList($basePath, &$mediaList);
  2773. foreach ($mediaList['path'] as $key=>$fPath) {
  2774. getMediaRecord($fPath, &$mediaRecord);
  2775. $selected = $media_id == $mediaRecord['media_id'];
  2776. $resultText .= '<li'.($selected?' class="open"':'').'>';
  2777. $resultText .= '<span class="text"><span class="media'.($selected?' selected':'').'">'.cleanWebString($mediaRecord['media_short'].' - '.$mediaRecord['media_work'], FIELD_STRING_LENGTH).SYS_DBL_SPACE.'</span></span>';
  2778. $resultText .= '<a href="#" title="Aggiorna" class="update"><span class="hidden">Aggiorna</span></a>';
  2779. $resultText .= '<a href="#" title="Elimina" class="delete"><span class="hidden">Elimina</span></a>';
  2780. $resultText .= '</li>';
  2781. };
  2782. $resultText .= '<li class="add"><span class="text">aggiungi Media...</span></li>';
  2783. $resultText .= '</ul>';
  2784. };
  2785. };
  2786. };
  2787. return $resultText;
  2788. };
  2789. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *